By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,194 Members | 884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,194 IT Pros & Developers. It's quick & easy.

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

P: n/a
while (infile_io.getline (buffer, sizeof(buffer))
{
// Stuff
}

How can one know what was a last character in the stream : newline or EOF?
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"
<al****@big-foot.com> wrote,
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?

Jul 23 '05 #2

P: n/a

"David Harmon" <so****@netcom.com> wrote in message news:42***************@news.west.earthlink.net...
On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"
<al****@big-foot.com> wrote,
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?


Function read_using_io_getline() at http://groups-beta.google.com/group/...00e587611b957e
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';
}
-----------------------------------------------

--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn


Jul 23 '05 #3

P: n/a

"Alex Vinokur" <al****@big-foot.com> wrote in message news:36*************@individual.net...

"David Harmon" <so****@netcom.com> wrote in message news:42***************@news.west.earthlink.net...
On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"
<al****@big-foot.com> wrote,
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?


Function read_using_io_getline() at http://groups-beta.google.com/group/...00e587611b957e
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/...b88c62ebef8ec9
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.