I have a binary file which contains doubles of size of 8 bytes. I want to read the doubles into a vector<double>
, see below
ifstream infile("x.dat", ios::binary);
vector<double>data(filesize/8, 0.0);
for(int i=0; i< (filesize/8); ++i)
{
infile.read( (char *) (&data[i]), sizeof(double) );
}
I know this would work if data was a C
array, but not sure if this will work for vector
, since vector
contains more stuff than a C
array(vector
has methods), does the address &data[i]
mean the address of the data member of the ith element?