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

后端 未结 5 2167
忘了有多久
忘了有多久 2021-02-08 14:09

I\'m writing a program on a Linux platform that is generating text files that will be viewed on, inevitably, a Windows platform.

Right now, passing std::endl

5条回答
  •  醉话见心
    2021-02-08 14:36

    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.

提交回复
热议问题