永发信息网

VC++关于结构体变量赋初值的问题?

答案:2  悬赏:0  手机版
解决时间 2021-02-16 02:02
  • 提问者网友:太高姿态
  • 2021-02-15 11:13
程序如下:为何编译出现错误提示:error C2552: 'stu' : non-aggregates cannot be initialized with initializer list。请高手指点。

#include
#include
using namespace std;
struct Student
{
int num;
string name;
float score[3];
}stu={12345,"lifeng",80,90,100};

int main()
{
void print(Student *);
Student *pt=&stu;
print(pt);
return 0;
}

void print(Student *p)
{
cout<num<<" "<name<<" "<score[0]<<" "<score[1]<<" "<score[2]<}
最佳答案
  • 五星知识达人网友:山君与见山
  • 2021-02-15 11:29
gcc编译通过的啊,你试试把string name改成char name[50]看看
全部回答
  • 1楼网友:一叶十三刺
  • 2021-02-15 11:39
inet_addr的参数,就是一个char *。如果你的工程是多字节模式(非unicode),可以这样用,只需要去掉格式化字符串中的双引号就可以了。 cstring.format("%u.%u.%u.%u", nfield0,nfield1, nfield2, nfield3); s_addr = inet_addr(cstring.getbuffer(0));
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯