注册 登录
编程论坛 C++教室

为什么不能初始化?

糊涂无罪 发布于 2012-06-12 19:53, 825 次点击
#include <iostream>
#include <iomanip>
#include<string>
using namespace std;
struct student {
    int num;
    string name;
    char sex;
    int age ;
};
int main(){
    student stu={111,"liu",'F',12};
    cout<<stu.num<<endl;
    cout<<stu.name<<endl;
    cout<<stu.sex<<endl;
    cout<<stu.age<<endl;
    return 0;
}
8 回复
#2
m21wo2012-06-12 20:00
有问题吗??没啥问题啊
#3
糊涂无罪2012-06-12 20:05
student stu={111,"liu",'F',12};这一行显示下面的错误:
'stu' : non-aggregates cannot be initialized with initializer list
#4
m21wo2012-06-12 20:07
鉴定 没啥问题 我机子运行没问题
#5
糊涂无罪2012-06-12 20:35
我用的vc6
#6
xl06070315112012-06-14 00:49
把 string name;改为char name[10];就可以初始化了
#7
liudw22012-06-14 08:44
可以初始化啊,我的用的是codeblocks编译器
#8
yang400b2012-06-14 18:15
是对的,我也是VC6啊,能通过啊。
#9
梦ambious2012-06-15 11:26
感觉没问题呀!!!
1