Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <fstream> // Contains the fstream object we'll be using.
  2. #include <vector> // std::vector for storing things
  3. #include <string> // std::string type
  4. #include <iostream> // std::cout
  5.  
  6. int main(int argc, char** argv)
  7. {
  8. // Create our objects.
  9. std::fstream fileObject("FileToRead.txt", std::ios::in);
  10. std::vector<std::string> fileLines;
  11.  
  12. // See if we opened the file successfully.
  13. if (fileObject.is_open())
  14. throw "File failed to open!"
  15.  
  16. // Read the lines in the file
  17. std::string buffer;
  18. while (std::getline(fileObject, buffer))
  19. fileLines.push_back(buffer);
  20.  
  21. // Now that we're done reading the file, we can close it
  22. fileObject.close();
  23.  
  24. // Print out the contents of the file
  25. for(int i = 0; i < fileLines.size(); ++i)
  26. std::cout << fileLines[i] << std::endl;
  27.  
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement