473,735 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

while (infile_io.getl ine (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 4360
On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"
<al****@big-foot.com> wrote,
while (infile_io.getl ine (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.we st.earthlink.ne t...
On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"
<al****@big-foot.com> wrote,
while (infile_io.getl ine (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_g etline() 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_g etline() -----
if (infile_io.fail ())
{
infile_io.clear (~(ios_base::fa ilbit | ~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******** *****@individua l.net...

"David Harmon" <so****@netcom. com> wrote in message news:42******** *******@news.we st.earthlink.ne t...
On Wed, 2 Feb 2005 08:17:00 +0200 in comp.lang.c++, "Alex Vinokur"
<al****@big-foot.com> wrote,
while (infile_io.getl ine (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_g etline() 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_g etline() -----
if (infile_io.fail ())
{
infile_io.clear (~(ios_base::fa ilbit | ~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_g etline() 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
3105
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 stop line input?
3
573
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
3308
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 implemntation of basic_streambuf and from basic_iostream. I am then using the function getline. This works fine using '\n' or any other character as the delimiter for getline().
2
6265
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); } I've tried this on two text files, one whose last line concluded with a
1
2419
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 form of getline getline(cin, string)
6
3815
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|| dfdg' so here my program does not go beyond the 2nd '|'. i am using ifstream to read the file. somehow check for eof() gets passed although end of file is not there. i am using
3
25209
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 vector array of strings, but i cant get stringstream working :(
11
13490
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 string is contained. From reading through posts to this list it seems that failbit gets set if there is a format error whilst reading. Is it bad form to reading binary data into a char array? Is this why my function below doesn't work? void...
5
15472
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 newlines in the result (I suspect they look only for the '\n'). * Is there a quick way I can tell either function to gobble up both Windows-style and Unix-style newlines? * If not, what would be an efficient way of getting rid of them? ...
0
8958
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6045
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3269
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2186
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.