In C++, which would be faster if repeated, say, 5000 times:
cout << \"text!\" << endl;
or
my_text_file <<
Writing the same amount of data, with the same buffer size to the console will most definitely be faster than writing to a file.
You can speed up your write speed (both for console output, and file output) by not writing out the buffer with every line (i.e.- don't use std::endl after every line, as it both adds an endline to the stream, and writes the buffer). Instead use "\n" unless you need to ensure the buffer is output for some reason.