c++ / endline

Torment

Veteran X
I'm currently doing this:
{

ifstream inf( "file" );
for( inf >> string; < ? > ; inf >> string )
etc.

}

at < ? >, how do I check for the end of the line, or will this method not work? It seems like >> is treating the end of a line just as a space, that is, as a delimiter, and so the return values between "ECS40 " and "ECS40\n" would be the exact same. Am I wrong? Is there a way to spot the EOL?
 
Damn java, my c++ skills are now non-existent.

IOstreams ignores whitespace as default, and \n counts as whitespace.

You could use an unformatted stream function

char buffer[80];
cin.get(buffer, 80, '\n');

Which would read everything into the buffer until it sees a newline char, not including the newline.

Then afterwards:

char c;
cin.get(c);

Would extract the newline character.

Or

cin.unsetf(ios::skipws);

Would turn off white space skipping altogether.
 
yeah, my prof. specified: no char declerations, arrays, pointers - you have to do it all using strings & iterators. worked around it using strnigs & getline (ifstream form) - thx for help guys :>

btw ss - is filename.eol() just a boolean? never seen that before
 
Back
Top