View Full Version : sstream
mickey
29th April 2008, 21:36
Hallo,
I'm trying to pasrse a stringstream but one problem:
int ch = sStream.get();
if( sStream.eof() )
return 1; //this seems doens't work
I see that the if is never "true" and when the sstream is end, ch assume '253'; why this?
mickey
1st May 2008, 00:23
Hello,
I reformulate the question in one other way:
see this piece of code:
ifstream file (name, ios::binary);
file.seekg (0, ios::end);
size = file.tellg();
_buffer = new char [size];
file.seekg (0, ios::beg);
file.read (_buffer, size);
//_buffer[size] = '\0';
cout << "size " << size << endl;
cout << " _buffer\n\n" << _buffer << endl;
I open this file and then, when I print _buffer, I see at its end "strange" characters; the only way to get out they, is to put the '\0' at size position. Is it right this or I'm doing wrong anything?
thanks a lot
mickey
2nd May 2008, 21:32
Could anyone help me to do this simple thing, please?
mickey
3rd May 2008, 23:19
I opt for this solution. It seems work proper:
ifstream file (name, ios::binary); //binary mode
file.seekg (0, ios::end);
size = file.tellg();
_buffer = new char [size+1]; //one more char
file.seekg (0, ios::beg);
file.read (_buffer, size); //read doens't set 'end' delimiter
_buffer[size] = '\0';
(The problem was round CR + LF windows delimiters and the read())
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.