473,840 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(mySockSt ream, 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(mySockSt ream, 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 3312
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(mySockSt ream, 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(mySockSt ream, 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
9996
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
3110
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:
18
8269
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 <iostream> #include <fstream> #include <cstdlib> #include <string>
4
353
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
3822
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
25222
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
13509
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
15482
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
9860
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
9699
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10601
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
10658
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
10300
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...
0
7023
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();...
1
4498
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
2
4072
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.