473,386 Members | 1,799 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,386 software developers and data experts.

getline() and a '\0' as a delimiter

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().

eg.
TCPSockSteam mySockStream;

//send some request
....

//get thre response
std::string str;
geline(mySockStream, str, '\n');

However, the peer I am working with is a Macromedia Flash based XML
socket aplication. These terninate their messages with a closing '\0'
character, so it would be nice to use getline to read a line from the
beginning until a '\0' is reached (much the same as '\n' but with '\0')

However, when I try and use code as below:

geline(mySockStream, str, '\0');

the message is never recieved. My knowlege of the iostream libraries
internal mechanics is not great, so I guess what I'm asking is how they
deal with '\0' in the context of getline and streams. I'm guessing from
the above not the same as other non-null characters...

Any help is much appreciated.

Cheers
Chris

Jul 23 '05 #1
1 3280
Apologies - a nights sleep and all has worked out fine.

Sorry for wasting anyones time...

Chris

Chris Coleman wrote:
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().

eg.
TCPSockSteam mySockStream;

//send some request
...

//get thre response
std::string str;
geline(mySockStream, str, '\n');

However, the peer I am working with is a Macromedia Flash based XML
socket aplication. These terninate their messages with a closing '\0'
character, so it would be nice to use getline to read a line from the
beginning until a '\0' is reached (much the same as '\n' but with '\0')

However, when I try and use code as below:

geline(mySockStream, str, '\0');

the message is never recieved. My knowlege of the iostream libraries
internal mechanics is not great, so I guess what I'm asking is how they
deal with '\0' in the context of getline and streams. I'm guessing from
the above not the same as other non-null characters...

Any help is much appreciated.

Cheers
Chris

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Schumacher | last post by:
Is there a way to set the delimiter to the "enter" key? I've tried the ASCII values for carriage return, line feed, form feed, and even null but it doesn't work. Thanks. -==Kensu==-
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:
18
by: Amadeus W. M. | last post by:
I'm trying to read a whole file as a single string, using the getline() function, as in the example below. I can't tell what I'm doing wrong. Tried g++ 3.2, 3.4 and 4.0. Thanks! #include...
4
by: MC felon | last post by:
getline isn't working..... what's wrong with this code? #include <iostream> #include <string> #include <conio2.h// ignore this.. my old habits class base { int x,y;
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.