Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string line;
- ifstream input("books.txt");
- vector<Books>id;
- vector<Books>title;
- vector<Books>author;
- vector<Books>category;
- vector<Books>copies;
- while(getline(input, line))
- {
- stringstream strStream(line);
- string id, title, author, category, copies;
- // Read tokens in this line one by one
- getline(strStream, id, '|');
- getline(strStream, title, '|');
- getline(strStream, author, '|');
- getline(strStream, category, '|');
- getline(strStream, copies, '|');
- // We need to convert the number of copies, and may be ID, to integers
- int idNum, copiesNum;
- stringstream idConverter(id);
- idConverter >> idNum;
- stringstream copiesConverter(copies);
- copiesConverter >> copiesNum;
- Books book1(idNum, title, author, category, copiesNum);
- id.push_back(idNum);
- title.push_back(title);
- author.push_back(author);
- category.push_back(category);
- copies.push_back(copiesNum);
- //books userBooks(id, title, author, category, copies);
- cout << idNum << ", " << title << ", " << author << ", " << category << ", " << copiesNum << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement