This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: memort stream
- To: libstdc++ at sources dot redhat dot com
- Subject: Re: memort stream
- From: Brad Garcia <garsh at home dot com>
- Date: Thu, 4 Oct 2001 16:06:21 -0400 (EDT)
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