Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <sstream>
- #include <utility>
- int main()
- {
- std::string input_file_name;
- std::cout << "\n Enter complete file path(with name): ";
- std::getline(std::cin, input_file_name);
- std::fstream inFile(input_file_name, std::ios::in);
- if (!inFile.good())
- std::cout << "\n File not found.";
- std::vector<std::pair<int,int>> books;
- while(inFile) {
- std::string line;
- std::getline(inFile,line);
- std::stringstream ss(line);
- int book_id, score;
- ss >> book_id >> score;
- books.push_back(std::make_pair(book_id,score));
- }
- inFile.close();
- std::for_each(books.begin(), books.end(), [](std::pair<int,int> x) {
- std::cout << "\n Book ID:" << x.first << " Score: " << x.second; });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement