jeudi 5 mars 2015

Reading a file into a vector all at once


Is this a good idea for reading into a std::vector, or is there some gotcha here:



using namespace std;
ifstream file("blah.dat", ios::binary);

vector<T> v(N);

file.read(static_cast<char*>(v.data()), N * sizeof(T));


Does the vector standard allow me to do this to populate a vector? For simplicities sake, let us assume that T is a Plain Old Data Type.




Aucun commentaire:

Enregistrer un commentaire