I've been trying to perform what should be the relatively simple task of reading a line of text from a file and saving it into an array. Unfortunately this has just not been working and instead the program simple does not read anything in at all. This is the sort of code I am trying to use:
ifstream in_stream;
int x=0;
string array[150]
in_stream.open("file.txt");
while(!in_stream.eof()){
in_stream>>array[x];
x++;
}
I have also tried to use getline as below:
ifstream in_stream;
int x=0;
string array[150]
in_stream.open("file.txt");
while(!in_stream.eof()){
getline(in_stream, array[x]);
x++;
}
Neither mode works and will not read anything into the array but rather leaves it blank... I am just not sure what is wrong so if someone can help that'd be grand!
std::vectorinstead of an array. Then, you don't have to worry about size of the file.string array[150]in both examples.