My Code:
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string index[8];
int main() {
int count = 0;
ifstream input;
//input.open("passData.txt");
while (true) {
input.open("passData.txt");
if (!input) {
cout << "ERROR" << endl;
system("pause");
exit(-1);
}
else {
if (input.is_open()) {
while (!input.eof()) {
input >> index[count];
count++;
}
}
for (int i = 0; i < 8; i++) {
cout << index[i] << endl;
}
}
input.close();
}
return 0;
}
My approach: opening the file in the beginning and then close it as soon as the lines where read. Also every line should be a single entry in the array.
However, I get an error in a file called "xutility" in an iterator. The output is the "passData.txt" file, only that its read once and then the error appears.
So, my question: how can I read every line of the file in an array entry, in a loop?
Thank you!