Advertisement
Guest User

book_read.cxx

a guest
Feb 24th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. #include <sstream>
  7. #include <utility>
  8.  
  9.  
  10. int main()
  11. {
  12.     std::string input_file_name;
  13.     std::cout << "\n Enter complete file path(with name): ";
  14.     std::getline(std::cin, input_file_name);
  15.     std::fstream inFile(input_file_name, std::ios::in);
  16.     if (!inFile.good())
  17.         std::cout << "\n File not found.";
  18.    
  19.     std::vector<std::pair<int,int>> books;
  20.     while(inFile) {
  21.         std::string line;
  22.         std::getline(inFile,line);
  23.         std::stringstream ss(line);
  24.         int book_id, score;
  25.        
  26.         ss >> book_id >> score;
  27.         books.push_back(std::make_pair(book_id,score));        
  28.     }
  29.     inFile.close();
  30.    
  31.     std::for_each(books.begin(), books.end(),  [](std::pair<int,int> x) {
  32.         std::cout << "\n Book ID:" << x.first << " Score: " << x.second; });
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement