\n 和 std::endl 的区别

2023-07-10,,

std::cout << std::endl;

等价于

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

除了写入换行符,std::endl 还会刷新缓冲区。除非程序对于性能十分敏感,不然使用 \n 或者 std::end 差别不大。

参考资料

What’s the difference between “\n” and “endl” in C++, when both do the same task?
"std::endl" vs "\n"

\n 和 std::endl 的区别的相关教程结束。

《\n 和 std::endl 的区别.doc》

下载本文的Word格式文档,以方便收藏与打印。