vc6.0中无法在struct中使用string解决方案
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;
}
#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;
}