#include <iostream>
#include <string>
#include <limits>
#include <fstream>
#include <vector>
int main()
{
std::vector vec;
std::string content;
ifstream datafile("ConsoleTest/data.txt");
if (!datafile.is_open()) // <--- Changed.
{
//std::cout<<... Error mesage of your choice.
std::this_thread::sleep_for(std::chrono::seconds(3)); // Requires header files "chrono" and "thread"
exit(1); // <--- No reason to continue.
}
while (getline(datafile, content)) // <--- Will read the entire file.
{
// <--- Best to put content into a vector or array.
vec.emplace_back(content);
// Not really needed.
//string line0;
//string line1;
}
datafile.close();
// Used to keep the console window open before the return ends the program.
// The next line may not be needed. If you have to press "enter" to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue";
std::cin.get();
return 0;
}
This should work unless I really missed something, but i do not think so. The vector information is giving me a problem at the moment. I think I need to shut everything down and restart my computer. The I will try again.