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

关于结构体中使用std:string 的有关问题

2013-09-26 
关于结构体中使用std::string 的问题#include iostream#include string#include cstringusing names

关于结构体中使用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;

最好别在结构中放类,

热点排行