关于结构体中使用std:string 的有关问题
关于结构体中使用std::string 的问题
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
struct List
{
std::string name;
int number;
float Chinese;
float Math;
float English;
};
int main()
{
List A=
{
"Eric.Cui",
1132201330,
92,
98,
94
};
cout<<A.name<<endl
<<A.number<<endl
<<A.Chinese<<endl
<<A.English<<endl
<<A.Math<<endl
<<"Total score is: "
<<A.Chinese+A.English+A.Math
<<endl;
return 0;
}
编译器显示F:\MSDev98\MyProjects\Struct\Struct.cpp(19) : error C2552: 'A' : non-aggregates cannot be initialized with initializer list
执行 cl.exe 时出错.
请指教
------解决方案--------------------
新点的编译器没这问题,试了vs2012和MinGW 4.8 编译通过
不行加个构造函数吧
------解决方案--------------------
珍惜生命,远离VC6;
最好别在结构中放类,
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
struct List
{
std::string name;
int number;
float Chinese;
float Math;
float English;
};
int main()
{
List A=
{
"Eric.Cui",
1132201330,
92,
98,
94
};
cout<<A.name<<endl
<<A.number<<endl
<<A.Chinese<<endl
<<A.English<<endl
<<A.Math<<endl
<<"Total score is: "
<<A.Chinese+A.English+A.Math
<<endl;
return 0;
}
编译器显示F:\MSDev98\MyProjects\Struct\Struct.cpp(19) : error C2552: 'A' : non-aggregates cannot be initialized with initializer list
执行 cl.exe 时出错.
请指教
------解决方案--------------------
新点的编译器没这问题,试了vs2012和MinGW 4.8 编译通过
不行加个构造函数吧
------解决方案--------------------
珍惜生命,远离VC6;
最好别在结构中放类,