Thread: string & stringstream issue/Q?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Location
    Australia
    Posts
    55

    string & stringstream issue/Q?

    hi,

    I'm trying to improve some file loading & have the following;

    Code:
            fHandle.seekg(0,std::ios::end); ////fHandle is fstream.
            std::streampos length = fHandle.tellg();
            fHandle.seekg(0,std::ios::beg);
    
            vector<char> buffer(length);
            fHandle.read(&buffer[0],length);
    
            stringstream streambuffer;
            //streambuffer.rdbuf()->pubsetbuf(&buffer[0],length); //1.0 crashes with this on large files ? Memory usage also increases substantially.
    
            //2.0 compiles & loads file except has issue with extracting data beyond first lot of bytes.
            string stringtemp = &buffer[0];
            streambuffer.str(stringtemp);
    
    
    //data extraction
    	unsigned int Data = 0;
    	int filepos = 0;
    	streambuffer.seekg(filepos);
            streambuffer.read((char*)&Data,4);
    //data beyond this can not get extracted ? i.e. following will not extract data properly.
    
    	filepos = 4;
    	streambuffer.seekg(filepos);
            streambuffer.read((char*)&Data,4);

    Problem is, one (1) alternative crashes on large files. The second (2) method has an issue with extracting data. So I'm wondering what am I doing wrong; or even, if there's a better/more efficient way of handling this.

    Cheers
    Last edited by Tropod; 01-15-2011 at 12:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM