Store one book data via pointer. Use function to initialize the data given by user.
#include <iostream>
#include <string>
// Store one book data via pointer.
// Use function to initialize the data given by user.
struct Book {
std::string name;
int code;
};
void Init(Book * book, std::string name, int code) {
book->name = std::move(name);
book->code = code;
}
int main() {
Book * stored = new Book();
std::string name;
int code;
std::cout << "Enter name: ";
std::getline(std::cin, name);
std::cout << "Enter code: ";
std::cin >> code;
Init(stored, name, code);
std::cout << stored->name << " " << stored->code << '\n';
delete stored;
return 0;
}
Comments
Leave a comment