What is the most elegant way to write a text/binary file with c++?
I found some good results on reading e.g.: Read txt with iterators and preallocation , or read into containers . So I wondered how would I write most elegant a std::string into a file? Edit: When reading I can preallocate space for the string via seek and tellg, since I know the size of the string, how could I tell the filesystem how much I want to write? Here's a tiny example on how to output a std::string , but you should really read up on fstream #include <iostream> #include <fstream> #include <string> int main(int argc, char *argv[]) { std::string s("writemeout"); std::ofstream outfile(