Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream> // Contains the fstream object we'll be using.
- #include <vector> // std::vector for storing things
- #include <string> // std::string type
- #include <iostream> // std::cout
- int main(int argc, char** argv)
- {
- // Create our objects.
- std::fstream fileObject("FileToRead.txt", std::ios::in);
- std::vector<std::string> fileLines;
- // See if we opened the file successfully.
- if (fileObject.is_open())
- throw "File failed to open!"
- // Read the lines in the file
- std::string buffer;
- while (std::getline(fileObject, buffer))
- fileLines.push_back(buffer);
- // Now that we're done reading the file, we can close it
- fileObject.close();
- // Print out the contents of the file
- for(int i = 0; i < fileLines.size(); ++i)
- std::cout << fileLines[i] << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement