Results 1 to 4 of 4

Thread: sstream

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default sstream

    Hallo,
    I'm trying to pasrse a stringstream but one problem:
    Qt Code:
    1. int ch = sStream.get();
    2. if( sStream.eof() )
    3. return 1; //this seems doens't work
    To copy to clipboard, switch view to plain text mode 
    I see that the if is never "true" and when the sstream is end, ch assume '253'; why this?
    Regards

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: fstream

    Hello,
    I reformulate the question in one other way:
    see this piece of code:
    Qt Code:
    1. ifstream file (name, ios::binary);
    2. file.seekg (0, ios::end);
    3. size = file.tellg();
    4. _buffer = new char [size];
    5. file.seekg (0, ios::beg);
    6. file.read (_buffer, size);
    7. //_buffer[size] = '\0';
    8. cout << "size " << size << endl;
    9. cout << " _buffer\n\n" << _buffer << endl;
    To copy to clipboard, switch view to plain text mode 
    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
    Regards

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: sstream

    Could anyone help me to do this simple thing, please?
    Regards

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: fstream

    I opt for this solution. It seems work proper:
    Qt Code:
    1. ifstream file (name, ios::binary); //binary mode
    2. file.seekg (0, ios::end);
    3. size = file.tellg();
    4. _buffer = new char [size+1]; //one more char
    5. file.seekg (0, ios::beg);
    6. file.read (_buffer, size); //read doens't set 'end' delimiter
    7. _buffer[size] = '\0';
    To copy to clipboard, switch view to plain text mode 
    (The problem was round CR + LF windows delimiters and the read())
    Regards

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.