views:

279

answers:

1

hello,

i am reading in a binary file via the usual c++/STL/iostream syntax. i am copying the whole content into an dynamically allocated char array and this works fine so far.

but since i want to serve parts of the content as lines to another part of the program, i think it would be better/easier to stick to streams because i don't want to hack around with cstring functions and pointers.

my question now is, how can i store the read in memory. in a stringstream? or in a string? which fits better? are there any advantages or disadvantages of one over the other?

thanks in advance!

+1  A: 

If you want to read from it as a stream, you might as well read directly from the file to the stringstream:

std::stringstream data;
data << input_file.rdbuf();

That reads the entire contents of 'input_file' into 'data'. You can read the data from there like you would any other stream.

Jerry Coffin
thanks, already got that.the question is now is it wise to store a stringstream as a kind of memory/char buffer in my class? or should i use a string?
didito
and what about std::stringbuf?
didito
Lacking a specific reason to do otherwise, I'd just store the stringstream.
Jerry Coffin