这是一个 struct 简单的C程序,但我不太明白我做错了什么,因为输出不是我想要的,
P1个
#include<stdio.h>
struct book
{
char name[10];
char author[10];
int refno;
};
//passing whole structure variable
void display(struct book b)
{
printf("%s %s %d",b.name,b.author,b.refno);
}
int main()
{
struct book b1={"LET US C","YPK",25};
display(b1);
}
在这里,这个命令可以很好地处理输出:
LET US C YPK 25
--------------------------------
Process exited after 0.3952 seconds with return value 0
Press any key to continue . . .
如果我试一试,会有BUT
struct{
// element -1;
//element -2;
//element-3;
}b1;
/*then*/
int main()
{
b1={"LET US C","YPK",25};
display(b1);
它显示错误消息:-
1:[Warning] extended initializer lists only available with -std=c++11 or -std=gnu++11
2:[Error] no match for 'operator=' (operand types are 'book' and '<brace-enclosed initializer list>')
3:[Note] candidate is:
4:[Note] book& book::operator=(const book&)
5:[Note] no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const book&'
如果我try 执行以下操作,将显示相同的消息:
struct book
{
//elements declarations as p1
}b[10];
int main()
{
b[1]={"LET US C","YPK",25};
display(b[1]);
}
OR WITH个
struct book
{
//elements declarations as p1
};
int main()
{
struct book b[10];
b[1]={"LET US C","YPK",25};
display(b[1]);
}
那么问题出在哪里呢?
实际上,我的主要目标是定义 struct 数组,如倒数第二和倒数第二部分所示 方法,但它似乎不起作用,所以请帮助>;