有人可以帮助我吗?结构和阵列的初始化器太多
两个,我解决不了的错误:
- 太多的初始化和
- 类型前面的 '日期'
这是一个头文件book.h
struct date
{
int date; >>>>the type(s preceding'date'),don't know what is this??
int month;
int year;
};
typedef struct {
char book_name[51];
char book_ID[7];
char author[31];
char publisher[31];
struct date book_date;
double price;
}BOOK;
这是一个.cpp
文件
void main()
{
int i;
BOOK bk_detail[10] ={
{"Harry Potter","B1001","JK ROWLING","Little Brown",{30,6,1997},56.00},
{"Me Before You","B1002","Jojo Moyer","Penguin Group",{3,6,2004},58.00},
{"Game Of Throne","B1003","George RR Martin","Snow Dany",{4,4,1990},69.00},
{"Maze Runner","B1004","James Dashner","Chicken Mouse",{3,3,2003},55.00},
{"Papertown","B1005","John Green","Dutton Penguin",{16,8,2008},47.00},
{"Twilight","B1006","Stephenie Meyer","Little Brown",{12,7,2005},56.00},
{"The Hunger Game","B1007","Suzanne Collins","Scholastic Corporation",{3,9,2006},69.00},
{"No Man Sky","B1008","Nathan Stuart","Littlefinger Group",{4,8,2014},55.00},
{"Resist the Temptation","B1009","Jon Snow","The Night Watch",{8,9,1998},69.00},
{"To Code","B1010","Daenerys Targaryen","Dragons BB",{5,3,1997},56.00}
};
FILE*books_detail=fopen("book_detail.bin","wb");
if (books_detail == NULL)
{
printf("ERROR...\n");
exit(-1);
}
fwrite(&bk_detail,sizeof(bk_detail[0]),10,books_detail);
fclose(books_detail);
}
我已经按照本教程的步骤,但看来,它仍然有错误,为什么仍然有这两个错误。(PS,我是新来的编码。 )
你使用什么编译器/操作系统? (我的gcc 5.4.1安装在Linux下接受,没有抱怨)。 –
@AdrianColomitchi:噢!真令人兴奋。我看着它,立即想到 - 那不可能是正确的......但是http://cpp.sh/8xj4r。好的,我不明白发生了什么事! OP:我们需要[mcve]和* complete *错误信息。 –
@MartinBonner“好吧,我不明白发生了什么事!”它适用于默认生成的构造函数。它不会在你想添加一个/任何构造函数的那一刻。 –