If I want to copy the contents of a file to a vector, I can do it like that:
std::ifstream file(\"path_to_file\");
std::vector buffer(std::istrea
Credit due to @sbi, I forgot about generate_n
.
The streambuf
inside file
has a function snextc
which returns the next character, qualifying it as a generator function, once its implicit this
argument is bound.
generate_n( back_inserter( buffer ), 42,
tr1::bind( tr1::mem_fn( &streambuf::snextc ), file.rdbuf() ) );
For vector
, just read directly. This is good for deque
or whatever.