创建结构的C中的数组++ [英] creating an array of structs in c++
本文介绍了创建结构的C中的数组++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建结构的数组。以下是对有效code?我不断收到一个之前的预期主要-EX pression{
标记错误。
INT的main()
{
INT暂停; 客户结构
{
INT UID;
字符串名称;
}; 顾客customerRecords [2];
customerRecords [0] = {25,鲍勃·琼斯};
customerRecords [1] = {26,吉姆·史密斯}; CIN>>暂停;
返回0;
}
解决方案
试试这个:
客户customerRecords [2] = {{25,鲍勃·琼斯},
{26,吉姆·史密斯}};
I'm trying to create an array of structs. Is the code below valid? I keep getting a expected primary-expression before '{'
token error.
int main()
{
int pause;
struct Customer
{
int uid;
string name;
};
Customer customerRecords[2];
customerRecords[0] = {25, "Bob Jones"};
customerRecords[1] = {26, "Jim Smith"};
cin >> pause;
return 0;
}
解决方案
Try this:
Customer customerRecords[2] = {{25, "Bob Jones"},
{26, "Jim Smith"}};
这篇关于创建结构的C中的数组++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文