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?
ofstreamin binary mode.. whether your data is binary or not, frankly) I would have usedvector<char>for the added feel-good factor. Any reason you didn't?string.stringseemed a convenient interface for manipulating buffers, like appending/substituting into another content etc. I though at one point to define abinaryStringasbasic_string<unsigned char>, but it required too much time for refactoring which I didn't have at that time. But could I use the<<operator withvector<char>?<<for binary data anyway, as my brain reads it as "formatted output" which is not what you're doing. Again, it's perfectly valid, but I just would not confuse my brain like that. :) The native appending is certainly useful, though.