本文共 828 字,大约阅读时间需要 2 分钟。
endl英语意思是end of line,即一行输出结束,然后输出下一行。
template <class charT, class traits>
std::basic_ostream<charT, traits>&
std::endl (std::basic_ostream<charT, traits>& strm)
strm.put(strm.widen(\n'));
其主要搭配iostream对象来使用,如cout、cerr等,其作用是:
1.将换行符写入输出流,其中Unix/Linux换行符是\n,Windows中是\r\n,MAC中是\r;
cout<<"the id is"<<endl <<2;
cout<<"the id is"<<i << endl;
std::endl(cout); // 等于 std::endl(std::cout);
std::endl(cout << "this id is" << i); // 等于 std::endl(std::cout << "this id is" << i);
其中第一句等同于:std::cout << std::endl; // 不能写成std::cout << endl;
第二句等于:std::cout << "this id is" << i << std::endl; // 如上所述
转载地址:http://jilws.baihongyu.com/