Why first getline doesnt work?
I have written a program, which is supposed to read 3 lines from a text file, the first is char, second string and thirs an integer. The input.txt is:
Code:
i
Arnold Schwarzenegger
60
And my code:
Code:
int main()
{
ifstream data("input.txt");
string name;
int age;
char instr;
data >> instr;
getline(data, name);
data >> age;
}
However, the getline does not read anything from the file, and after that, when the program processes to the next line of code, the 'data >> age' statement tries to read the 'Arnold Schwarzenegger' field into the age variable...
Why is that? Why does the getline read nothing? How do I make it work?