I have an std::string object containing binary data which I need to write to a file. Can ofstream f("name"); f << s; be problematic in any way? I need to read the data back exactly as it was originally.
I can of course use fwrite(s.c_str(), s.size(), 1, filep), are there any pros / cons to either method?
You should be ok as long as you open the ofstream for binary access.
Don’t forget to open your file in binary mode when reading the data back in as well.