vc6.0中无法在struct中使用string

najiushifeng2 2007-08-01 05:57:37
#include <iostream>
#include <string>
using namespace std;
struct people
{
double weight;
double tall;
int age;
std::string name;
char *native;
bool sex;
};
void check(bool s){if(s==1)cout<<"男"<<endl;else cout<<"女"<<endl;}
int main()
{
people Jack=
{
180.5,
179.3,
34,
"Jack",
"济南",
1
};
cout<<Jack.name<<endl;
cout<<Jack.native<<endl;
cout<<Jack.tall<<endl;
cout<<Jack.weight<<endl;
cout<<Jack.age<<endl;
check(Jack.sex);
return 0;
}
无论是std::string name;还是string name;都会报错,dev和vs2005里正常,我想在VC6.0里也能正常。
...全文
166 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yydrewdrew 2007-08-01
  • 打赏
  • 举报
回复
哦错了,这样吧:
#include <iostream>
#include <string>
using namespace std;
struct people
{
people(double t_weight,double t_tall,int t_age,string t_name, char *t_native,bool t_sex);
double weight;
double tall;
int age;
string name;
char *native;
bool sex;
};
people::people(double t_weight,double t_tall,int t_age,string t_name, char *t_native,bool t_sex)
{
weight = t_weight;
tall = t_tall;
age = t_age;
name = t_name;
native = t_native;
sex = t_sex;
};
void check(bool s){if(s==1)cout<<"男"<<endl;else cout<<"女"<<endl;}

int main()
{
struct people Jack(
180.5,
179.3,
34,
"Jack",
"济南",
1
);
cout<<Jack.name<<endl;
cout<<Jack.native<<endl;
cout<<Jack.tall<<endl;
cout<<Jack.weight<<endl;
cout<<Jack.age<<endl;
check(Jack.sex);
return 0;
}
yydrewdrew 2007-08-01
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
using namespace std;
struct people
{
static double weight;
static double tall;
static int age;
static string name;
static char *native;
static bool sex;
};

void check(bool s){if(s==1)cout<<"男"<<endl;else cout<<"女"<<endl;}

int main()
{
struct people Jack =
{
180.5,
179.3,
34,
"Jack",
"济南",
1
};
cout<<Jack.name<<endl;
cout<<Jack.native<<endl;
cout<<Jack.tall<<endl;
cout<<Jack.weight<<endl;
cout<<Jack.age<<endl;
check(Jack.sex);
return 0;
}
Tracy2007 2007-08-01
  • 打赏
  • 举报
回复
还是用visual stdio 2005吧
jixingzhong 2007-08-01
  • 打赏
  • 举报
回复
VC6 的问题 ...
jixingzhong 2007-08-01
  • 打赏
  • 举报
回复
用 char *

既然有 char *了,
就都用 char * 好了...

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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