Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1.     string line;
  2.     ifstream input("books.txt");
  3.    
  4.     vector<Books>id;
  5.     vector<Books>title;
  6.     vector<Books>author;
  7.     vector<Books>category;
  8.     vector<Books>copies;
  9.    
  10.     while(getline(input, line))
  11.     {
  12.         stringstream strStream(line);
  13.         string id, title, author, category, copies;
  14.  
  15.         // Read tokens in this line one by one
  16.         getline(strStream, id, '|');
  17.         getline(strStream, title, '|');
  18.         getline(strStream, author, '|');
  19.         getline(strStream, category, '|');
  20.         getline(strStream, copies, '|');
  21.        
  22.  
  23.         // We need to convert the number of copies, and may be ID, to integers
  24.         int idNum, copiesNum;
  25.         stringstream idConverter(id);
  26.         idConverter >> idNum;
  27.  
  28.         stringstream copiesConverter(copies);
  29.         copiesConverter >> copiesNum;
  30.  
  31.         Books book1(idNum, title, author, category, copiesNum);
  32.        
  33.         id.push_back(idNum);
  34.         title.push_back(title);
  35.         author.push_back(author);
  36.         category.push_back(category);
  37.         copies.push_back(copiesNum);
  38.        
  39.        
  40.        
  41.         //books userBooks(id, title, author, category, copies);
  42.    
  43.         cout << idNum << ", " << title << ", " << author << ", " << category << ", " << copiesNum << endl;
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement