C ++-字符串中的跨平台换行符

Abd*_*lah 6 c++ string cross-platform

当需要字符串中的换行符时,我使用\n字符

 int main()
 {
     string str = "Hello world\n";
 }
Run Code Online (Sandbox Code Playgroud)

是否\n跨平台?还是我需要使用宏在平台上调整其价值?

特别str是在将要写入文件或标准输出时。

小智 7

只要您在文本模式下读/写文本流或文件,\n就会被翻译成平台的正确序列。

http://en.cppreference.com/w/c/io