I have a char* variable:
// char* buffer; // ... fread (buffer, 1, lSize, pFile); // ...
How can I convert it to std::vector? Casting will get me an error.
To convert an array to vector, you can use the constructor of Vector, or use a looping statement to add each element of array to vector using push_back() function.
std::vector<char> data(buffer, buffer + size);
James McNellis answer is better if you can do it like that.
Why not use a std::vector
to begin with:
std::vector<char> buffer(lSize); std::fread(&buffer[0], 1, buffer.size(), pFile);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With