I'll see the C answer given earlier and raise a C++ answer for the same thing:
void write_text_to_log_file( const std::string &text )
"log_file.txt", std::ios_base::out | std::ios_base::app );
log_file << text << std::end;
It'll do the same thing with the bonus that if the file fails to open for whatever reason it won't crash in a steaming heap of undefined behaviour.
PS the important bits of logging for when you write your own are:
- flush after every message - std::endl does that
- close the file after every message - the fstream destructor does that