4 ms·
In C++, I've absolutely had to explicitly use std::endl while debugging to make sure that my debug messages actually were visible when they were supposed to be.
by LorenDB 3y ago
In C++, I've absolutely had to explicitly use std::endl while debugging to make sure that my debug messages actually were visible when they were supposed to be. Using std::flush also works if you don't want to force a newline. However, in my experience, printing a newline character via std::cout does not flush the stream.
- cwillu 3y agoMay not be the issue, but if you have your stdout piped into something or redirected to a file, you'll usually get a buffered stream, not a line-buffered one, in which case the \n won't trigger a flush.
- fransje26 3y agoWell, yes, that's by design, as std::cout is buffered. If you want to have visible debug information, you can either: - call << std::flush; - use << std::endl; which is basically equivalent to << "\n" << std::flush; - use std::cerr instead of std::cout, which is unbuffered.