Ray
2009-11-14 18:56:02 UTC
Hello,
The intent of the following code is to read the first 2 characters from each
line until EOF is reached. It does this correctly on the first line but
stores an empty string for all subsequent lines. Of course I an accomplish
this task in other ways but I was wondering why this approach didn't work.
Thanks
char buf[512];
while (!cin.getline(buf, 3).eof())
{
cout << buf << '\n';
cin.ignore(100, '\n');
}
The intent of the following code is to read the first 2 characters from each
line until EOF is reached. It does this correctly on the first line but
stores an empty string for all subsequent lines. Of course I an accomplish
this task in other ways but I was wondering why this approach didn't work.
Thanks
char buf[512];
while (!cin.getline(buf, 3).eof())
{
cout << buf << '\n';
cin.ignore(100, '\n');
}