首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

vc6.0中无法在struct中使用string解决方案

2012-03-11 
vc6.0中无法在struct中使用string#includeiostream#includestringusingnamespacestdstructpeople{dou

vc6.0中无法在struct中使用string
#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里也能正常。

[解决办法]
哦错了,这样吧:
#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;
}

热点排行