M
mathieu
Dear all,
I do not understand how to use the STL vector class with the
ifstream class. I would like to reserve a chunk of memory (no
initialization is required) and fill it with values from a file. As
far as I understand vector::reserve requires a subsequent call to
push_back or insert. However I do not see how I can do this in the
following example:
#include <fstream>
#include <vector>
int main(int argc, char *argv[])
{
const char *filename = argv[1];
std::ifstream is( filename );
const size_t l = 512;
std::vector<char> v;
v.reserve( l ); // need push_back or insert
is.read( &v[0], l ); // ?
return 0;
}
thanks for your help !
I do not understand how to use the STL vector class with the
ifstream class. I would like to reserve a chunk of memory (no
initialization is required) and fill it with values from a file. As
far as I understand vector::reserve requires a subsequent call to
push_back or insert. However I do not see how I can do this in the
following example:
#include <fstream>
#include <vector>
int main(int argc, char *argv[])
{
const char *filename = argv[1];
std::ifstream is( filename );
const size_t l = 512;
std::vector<char> v;
v.reserve( l ); // need push_back or insert
is.read( &v[0], l ); // ?
return 0;
}
thanks for your help !