C++中的cout

来源:互联网 发布:jstor数据库中文版 编辑:程序博客网 时间:2024/06/05 23:06

    cout是C++语言中iostream类的一个对象,cout有一个成员运算符函数operator<<,operato可以接受不同类型的运算符(重载);我们这样写:

    cout<<"hello world!";

    如果想要输出后回车到下一行,可以在这样写:

    cout<<"hello world"<<endl;

    endl是endl of line的缩写,即结束这一行输出后进入下一行。

    对比:

------------ 使用cout和endl,只换行一次

------------ 使用cout和endl,换行两次


cout的一些方法:

cout.precision();

cout.width();