我们知道endl是机械手,在内部将'\n'放入缓冲区,然后刷新缓冲区。endl是在哪里定义的?什么是endl,是宏、函数还是变量、类或对象?我如何定义我自己的endl机械手?
cout << "hello" << endl ; /*what is endl and where it is defined */发布于 2015-11-05 19:29:28
http://en.cppreference.com/w/cpp/io/manip/endl说:
在标头
<ostream>中定义
template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>& endl( std::basic_ostream<CharT, Traits>& os );如果我想编写我自己的endl操作程序,我需要编写什么代码?
如果您只想为std::ostream创建它,只需创建一个接受对std::ostream的引用并返回一个引用的函数。如果你想让它成为通用的,你可以让它像std::endl一样被简化。
https://stackoverflow.com/questions/33553091
复制相似问题