求教,不知道大家碰到过吗?

lixinqiang 2002-05-28 08:27:16
#include <string>
#include <iostream>

class x {
public:
string a ;
string b ;
};

int main(){
x x1;
x1.a = "sdfsdfsd";
cout<<x1.a;
}

编译时出错:
error C2146: syntax error : missing ';' before identifier 'a'
error C2501: 'string' : missing storage-class or type specifiers
error C2501: 'a' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier 'b'
error C2501: 'string' : missing storage-class or type specifiers
error C2501: 'b' : missing storage-class or type specifiers
不知道什么原因。
若用int代替string就没有此种问题。

...全文
35 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sandwish2000 2002-05-28
  • 打赏
  • 举报
回复
#include <string>
#include <iostream>

using namespace std;

class x
{
public:
string a;
string b;
};

int main(){
x x1;
x1.a = "sdfsdfsd";
cout<<x1.a;
return 0;
}
lixinqiang 2002-05-28
  • 打赏
  • 举报
回复
哈哈,这么简单,已经ok啦,开始还以为不是,早知道试试就好了。
thanks
joy8223 2002-05-28
  • 打赏
  • 举报
回复
在vc里可以用CString
qypass 2002-05-28
  • 打赏
  • 举报
回复
加上 using namespace std;

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧