I have a text.dat file with a content like this:
first example
1
second example
2
third example
3
and I want to read them as a string and an int respectively. Here's a simplified version of what I was trying to do:
ifstream fIn("text.dat", ios::binary);
string c;
while(getline(fIn, c)) {
cout << c << endl;
int n;
fIn >> n;
cout << n << endl;
}
This code only works in the first iteration of the while and then it prints a blank space and a 0. Like this:
first example
1
0
if I use only the string, without the int and the injection operator, I can print all the values properly, but I need the integer as an int type. How can I achieve this?