I would like to open from a file and then store the strings stored in the txt filed to an array.The txt file i want to open has 1 string on each line.So each line will be 1 string.What should i change here?
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
getchar();
return 0;
}