I am trying to read a file to a vector and I got to this nice post, which contains 2 methods of doing this.(I will ignore non-important lines)
std::ifstream testFile("testfile", std::ios::binary);
std::vector<char> fileContents((std::istreambuf_iterator<char>(testFile)),
std::istreambuf_iterator<char>());
std::vector<char> fileContents;
fileContents.assign(std::istreambuf_iterator<char>(testFile),
std::istreambuf_iterator<char>());
My code (C++ 11) suits a lot better for the second approach (I need the vector constructed very early), but from CPP documentation it seems that in the first solution, the constructor will add emplace-constructed values, compared to the "assign" method which will create new objects and add them to the vector, thus making copies.
Is there a solution to assign the vector later but without making copies?
Thanks