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

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top