I/O getline: which is a last character - delimiter or EOF?

A

Alex Vinokur

while (infile_io.getline (buffer, sizeof(buffer))
{
// Stuff
}

How can one know what was a last character in the stream : newline or EOF?
 
D

David Harmon

On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"
while (infile_io.getline (buffer, sizeof(buffer))
{
// Stuff
}

How can one know what was a last character in the stream : newline or EOF?

EOF is not a character.

Theoretically, cin.eof() might tell you what you want to know. But I
wouldn't trust it universally. Why do you care?
 
A

Alex Vinokur

David Harmon said:
On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"


EOF is not a character.

Theoretically, cin.eof() might tell you what you want to know. But I
wouldn't trust it universally. Why do you care?

Function read_using_io_getline() at http://groups-beta.google.com/group/comp.lang.c++/msg/4500e587611b957e
produces the same output in two diffrent situations:
1) the file ends by '\n' + EOF;
2) the file ends by EOF without '\n'.

I want the program to produce different output that corresponds to the file content (contene includes '\n'-s too).

----- Fragment of read_using_io_getline() -----
if (infile_io.fail())
{
infile_io.clear (~(ios_base::failbit | ~infile_io.rdst­ate ()));
}
else
{
// Here I would like to know if the file ends by 1) '\n' + EOF or 2) EOF without '\n'.
cout << '\n';
}
 
A

Alex Vinokur

Alex Vinokur said:
Function read_using_io_getline() at http://groups-beta.google.com/group/comp.lang.c++/msg/4500e587611b957e
produces the same output in two diffrent situations:
1) the file ends by '\n' + EOF;
2) the file ends by EOF without '\n'.

I want the program to produce different output that corresponds to the file content (contene includes '\n'-s too).

----- Fragment of read_using_io_getline() -----
if (infile_io.fail())
{
infile_io.clear (~(ios_base::failbit | ~infile_io.rdst­ate ()));
}
else
{
// Here I would like to know if the file ends by 1) '\n' + EOF or 2) EOF without '\n'.
cout << '\n';
}
-----------------------------------------------

Updated version of read_using_io_getline() can be seen at
http://groups-beta.google.com/group/comp.lang.c++/msg/04b88c62ebef8ec9
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top