getline() special

H

hauser

Hey,

first of all sorry for my bad english, but I'm from Germany

I found something special in the getline() function, I don't
understand.

If I use the getline function in case of an Excel-sheet or an image -
to get the image-data - the getline function breakes after a NULL
termination ( \0 )

fstream oFile_e;

oFile_e.open("BAB.xls",ios::in);

oFile_e.getline(chTest, 100,'\n');

BAB.xls containes the \0 from position 9 to 12

chTest is after the getline function only filled up to position 9
( after the first \0 )

--> no problem with the ios::binary mode. With this mode it's possible
to read the whole data.

But if I write out some chars in a file and some of them are \0, I can
read the whole data WITHOUT the ios::binary mode.

Do you understand that phenomenon?
 
V

Victor Bazarov

first of all sorry for my bad english, but I'm from Germany

I found something special in the getline() function, I don't
understand.

If I use the getline function in case of an Excel-sheet or an image -
to get the image-data - the getline function breakes after a NULL
termination ( \0 )

fstream oFile_e;

oFile_e.open("BAB.xls",ios::in);

oFile_e.getline(chTest, 100,'\n');

BAB.xls containes the \0 from position 9 to 12

chTest is after the getline function only filled up to position 9
( after the first \0 )

--> no problem with the ios::binary mode. With this mode it's possible
to read the whole data.

But if I write out some chars in a file and some of them are \0, I can
read the whole data WITHOUT the ios::binary mode.

Do you understand that phenomenon?

I think this is covered in the FAQ 5.8.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fstream, getline() and failbit 15
Chatbot 0
getline and EOF question 18
getline buffering 8
Rearranging .ply file via C++ String Parsing 0
while getline corrupting the stream 4
adapting getline 77
getline problem 10

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top