1.不适用typedef:
#include <iostream> #include <cstring> using namespace std; struct Books { char title[50]; char author[50]; char subject[100]; int book_id; }; int main() { struct Books book; strcpy(book.title, "C 教程"); strcpy(book.author, "Runoob"); strcpy(book.subject, "编程语言"); book.book_id = 12345; printf("书标题 : %s\n", book.title); printf("书作者 : %s\n", book.author); printf("书类目 : %s\n", book.subject); printf("书 ID : %d\n", book.book_id); system("pause"); return 0; }
2.使用typedef:
#include <iostream> #include <cstring> using namespace std; typedef struct Books { char title[50]; char author[50]; char subject[100]; int book_id; }; int main() { struct Books book; strcpy(book.title, "C 教程"); strcpy(book.author, "Runoob"); strcpy(book.subject, "编程语言"); book.book_id = 12345; printf("书标题 : %s\n", book.title); printf("书作者 : %s\n", book.author); printf("书类目 : %s\n", book.subject); printf("书 ID : %d\n", book.book_id); system("pause"); return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。