Data extraction from our struct Book_1 will be extremely easy.
To extract value for Title first we will target "row" Book_1, than dot symbol, and than a "column" we need:
cout << "Book_1 - Title: \t" << Book_1.Title << endl;
Following same logic, all other values can be extracted:
cout << "Book_1 - Author: \t" << Book_1.Author << endl;
cout << "Book_1 - Topic: \t" << Book_1.Topic << endl;
cout << "Book_1 - ID: \t" << Book_1.id_book << endl;
Full source:
#include <iostream>
#include <cstring>
using namespace std;
struct Books {
char Title[50];
char Author[50];
char Topic[100];
int id_book;
};
int main() {
struct Books Book_1;
strcpy(Book_1.Title, "Relativity T");
strcpy(Book_1.Author, "Albert E");
strcpy(Book_1.Topic, "Relativity");
Book_1.id_book = 4323;
cout << "Book_1 - Title: \t" << Book_1.Title << endl;
cout << "Book_1 - Author: \t" << Book_1.Author << endl;
cout << "Book_1 - Topic: \t" << Book_1.Topic << endl;
cout << "Book_1 - ID: \t" << Book_1.id_book << endl;
cout << "-------------------------------------" << endl;
return 0;
}
Result:
Book_1 - Title: Relativity T
Book_1 - Author: Albert E
Book_1 - Topic: Relativity
Book_1 - ID: 4323
-------------------------------------
Process returned 0 (0x0) execution time : 0.067 s
Press any key to continue.
No comments:
Post a Comment