Hello,
I'm reading a USB stick into an unsigned char vector.
Not a problem, Method 1 is obviously faster than Method 2.
As you can see I'm reading into a buffer and then putting the data into the vector.
In Method 1, would it be possible to read straight into the vector? If so, how?
Regards
Code:
std::vector <unsigned char> buff;
buff.reserve(size);
Code:
Method 1
//check on file size
unsigned char data[512];
infile.read((char *)&data, size);
for (int i = 0; i < size; i++)
{
buff.push_back(data[i]);
printf("%i - %c, ", i, data);
}
Code:
Method 2
unsigned char data[1];
for (int i = 0; i < size; i++)
{
if (infile.eof()) // check for EOF
{
printf("EOF reached\n");
cin.get();
exit (999);
}
infile.read((char *)&data, sizeof(data));
buff.push_back(data);
printf("%i - %c, ", i, data);
}