LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-20-2009, 03:03 AM   #1
naveentiptur
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Rep: Reputation: Disabled
Exclamation getline bug c++


Hi ,


istream->getline drops one character when it goes to read from one buffer to another buffer...

The code i am using is as below

char lineRead[1024];
istream * is = request->Instream();
is->getline(lineRead,1000,'\r');


request->Instream is an async buffer which reads 1024 bytes everytime..

Ex:

if the buffer is

first line.. 1024
second line ... abcdefgh
third line

if the 1000 bytes ends in the middle of the second line for example at 'c', then the next char 'd' gets droppped and it starts to read from 'e'
..


if I read the whole buffer using readsome() then it comes fine.. get() also gives same problem..


Can someone help me with this.. or any other method to read the buffer line by line..
 
Old 04-20-2009, 05:39 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi,

and welcome to LQ!

Works as designed ...

http://www.cplusplus.com/reference/i...tream/getline/
n-1 is *normal* behaviour.


Cheers,
Tink
 
Old 04-20-2009, 11:33 PM   #3
naveentiptur
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: Disabled
Unhappy Hi, But it drops a character in the middle of the line.

Hi,
But it drops a character in the middle of the line and not at the end ,
which presumably u must be thinking..

infact it drops whereever it is, when it goes from one chunk of bytes to another ..
did u get it??

Thanks,
Naveen
 
Old 04-20-2009, 11:35 PM   #4
naveentiptur
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: Disabled
Wink One more thing,

There is no problem with the buffer.. Because it works fine with readsome()..



Thanks,
Naveen
 
  


Reply

Tags
c++, getline



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'getline' questions cleopard Programming 3 07-09-2008 09:38 AM
Error in getline harrylee2003 Programming 8 08-04-2006 04:46 PM
getline hylke Programming 9 06-03-2004 01:24 PM
g++ and cin.getline() codeviking Programming 8 07-03-2003 07:42 AM
cin.getline adam_boz Programming 6 10-02-2002 08:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration