C++札记

1、

  • endl操作符作用就是将调用的数据用完后自动清空缓冲区,同时换行。

  • 而/n只是单纯的换行而已。
//the declaration of  endl
template<class _Elem,
    class _Traits> inline
    basic_ostream<_Elem, _Traits>&
        __CLRCALL_OR_CDECL endl(basic_ostream<_Elem, _Traits>& _Ostr)
    {    // insert newline and flush stream
    _Ostr.put(_Ostr.widen('\n'));
    _Ostr.flush();
    return (_Ostr);
    }

 在cout命令中是默认为没有缓冲的,所以说endl和'/n'在cout语句中的使用是没有区别的。

2、string::size()返回类型是 string::size::type ,因此不应与int,unsigned等类型运算。

3、切记:字符串字面量与string是不同的类型

 

posted on 2015-09-05 21:53  Perry333  阅读(155)  评论(0)    收藏  举报

导航