This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: memort stream



Levente Farkas wrote:
> not exactly:-( suppose I'd like to read a binary file's content into
> the memory once (to save file i/o operation in order to make it faster)
> than a factory create object which can initialize itself from the 
> binary stream. so I'd like to give the factory a stream which has 
> the content of the binary file. currently iy's not solvable with
> stringstream (but strstream), since istringstream.rdbuf()->pubsetbuf(..)
> do nothing:-( so what is the solution?

I think stringstream will work.

Here's a little example program that makes a copy of a file by first
copying the entire file into a stringstream, and then copying it
from the stringstream to the output file:

#include <fstream>
#include <sstream>

int main()
{
    std::stringstream memstream;
    std::ifstream infilestream("conf");
    memstream << infilestream.rdbuf();
    infilestream.close();

    std::ofstream outfilestream("conf2");
    outfilestream << memstream.rdbuf();
    outfilestream.close();
}


Brad Garcia


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]