Changing std::endl to put out CR+LF instead of LF Changing std::endl to put out CR+LF instead of LF windows windows

Changing std::endl to put out CR+LF instead of LF


std::endl is basicly:

std::cout << "\n" << std::flush;

So just use "\r\n" instead and omit the flush. It's faster that way, too!

From the ostream header file on endl:

This manipulator is often mistakenly used when a simple newline is desired, leading to poor buffering performance.


Opening a file in text mode should cause std::endl to be converted to the appropriate line ending for your platform. Your problem is that newline is appropriate for your platform, but the files you create aren't intended for your platform.

I'm not sure how you plan on overloading or changing endl, and changing its behavior would certainly be surprising for any developers new to your project. I'd recommend switching to win_endl (should be a simple search-and-replace) or maybe switching from a standard ostream to a Boost.Iostreams filtering stream to do the conversion for you.


Windows Notepad is pretty much the only Windows program you'll find that doesn't handle LF-only files properly. Almost everything else (including WordPad) handles LF-only files just fine.

This problem is a bug in Notepad.