I used a string (mystring) to put on it the content of a file :
std::ofstream fs("C:\\example.mp4",std::ios::binary);
fs << mystring;
fs.close();
this works with several examples and I wonder why ? (even with files that contains zeros like a png file for example), I mean the binary file is correctly saved on the HDD...
Otherwise, I used the size() method to determine the size of the data that the string contains in order to upload it,... I know that in some binary files there are zeros ('\O'), I read that this method is similar to length() so it stops counting if it finds a '\0' ? but even in that case my application works, I mean, size() gave me the true size of my data (binary file), for this case I want to precise that I use this type of construction :
//...
std::ifstream::pos_type fileSize = ifs.tellg();
std::vector<char> bytes(fileSize);
//...
myifstream.read(&bytes[0], fileSize);
file_content = std::string(&bytes[0], fileSize);
so size() will return the value of myifstream.tellg() ? and not counting until it finds a '\0' ??
in another situation, the server sends me data (char*), I used append(data,size) to copy them in the string... and it always works even if there are zeros....
I want to ensure that using a string object to manipulate a file content is safe. (file stream and size() )