In C++ storing and retrieving of character vector (vector<char>) of all zero value (i.e. '\0' or string terminator) from file

Solution 1:

You write the vector object itself, not the data wrapped by the vector (which is located on the heap).

You need to get a pointer to the data itself and write that:

Fpt.write(V.data(), V.size());

Similarly when you read the data, you need to read it into the wrapped data:

V = std::vector<char>(10);  // Reset the vector, remembering to set its size
Fpt.read(V.data(), V.size());