std::cout << std::endl; 等价于 std::cout << '\n' << std::flush; 除了写入换行符,std::endl 还会刷新缓冲区。除非程序对于性能十分敏感,不然使用 \n 或者 std::end 差别不大。 参考资...
先抓出std::endl的源代码: /** * @file ostream * @brief Write a newline and flush the stream. * * This manipulator is often mistakenly used when a simple newline is...
看C++Primer的时候看到的,然后去百度了一下; 比较明白的解释: 1、区别在于: \n只代表换行的转义字符 endl除了代表换行,还紧跟着清出缓冲槽 2、接下来我们看一下具体内容的辨析: 要明白\n和endl的区别,首先...