473,320 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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
3 4332
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

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: JustSomeGuy | last post by:
Getline has a delimiter character parameter that is used to say when input should stop. (std::cin.getline) However what do you do if you have multiple conditions/character on which you wish to...
3
by: salvo | last post by:
Hi, I'm having some trouble in parsing a simple text file which is formatted as follows: .... string\tstring\tstring\n .... I tried to parse it with the following statments:
1
by: Chris Coleman | last post by:
Hi, As some background, I have implemented a new stream object to work with tcp socket streams. I derive a new socket stream from basic_streambuf. I then derive a my sream object from my...
2
by: Mark P | last post by:
Consider the following snippet of code to read lines from a text file: ifstream file_stream( "some_file.txt"); string read_line; while( file_stream) { getline( file_stream, read_line); } ...
1
by: l46kok | last post by:
Just wondering, for character of arrays, you can set the delimiter manually like cin.getline(character array, size, delimeter) But for the STL string, apparently, you have to use the following...
6
by: ankit.kumar.agarwal | last post by:
I am facing a problem with getline I am reading a text file with a getline function the lines can have '|' as separator. everything works OK but in case if i have 2 delimitors in file '234||...
3
by: JackC | last post by:
Hi, How do i use stringstreams getline function to extract lines from an existing string? Say i have: string strlist = "line1\r\nLine2\r\nLine3\r\n"; I want to extract each line out into a...
11
by: rory | last post by:
I am reading a binary file and I want to search it for a string. The only problem is that failbit gets set after only a few calls to getline() so it never reaches the end of the file where the...
5
by: barcaroller | last post by:
I have a text file with mixed carriage returns ('\n' and '\r\n'). On Linux, both the std::string getline() global function and the std::iostream getline() member function are keeping some of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.