C++标准输出流

简介: C++标准输出流

标准输出流对象 cout

cout.flush()

cout.put()

cout.write()

cout.width()

cout.fill()

cout.setf(标记)

标准输出流常见api编程案例

#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
int main01(void)
{
    cout<<"hello world"<<endl;
    cout.put('h').put('e').put('l').put('l').put('e').put('\n');
    cout.write("hello world",4);
    printf("\n");
    char buf[] = "hello world";
    cout.write(buf,strlen(buf));
    printf("\n");
    cout.write(buf,strlen(buf)-6);
    printf("\n");
    cout.write(buf,strlen(buf)+6);
    printf("\n");
    return 0;
}
int main(void)
{
    //使用类成员函数
    cout<<"---let's go---"<<endl;
    cout.width(30); //设置下一次输出的宽度为30,默认右对齐
    cout.fill('*'); //因为指定了宽度,所以可以用fill来填充空白位置
    cout.setf(ios::showbase);   //输出时显示基数 0 0x
    cout.setf(ios::internal);   //将填充字符放到符号和数字之间
    cout<<hex<<123<<endl;
    cout<<"---end---"<<endl;
    //使用控制阈
    cout<<"<<<<< start >>>>>"<<endl;
    cout<<setw(30)
        <<setfill('*')
        <<setiosflags(ios::showbase)
        <<setiosflags(ios::internal)
        <<hex
        <<123
        <<endl;
    cout<<"<<<<<  end  >>>>>"<<endl;
    return 0;
}
相关文章
|
7月前
|
Linux C++ iOS开发
69 C++ - 标准输出流
69 C++ - 标准输出流
29 0
|
17天前
|
C++
C++程序标准输出流
C++程序标准输出流
25 1
|
C++ iOS开发
C++语言基础 例程 标准输出流
贺老师的教学链接  本课讲解 cerr流对象使用:解方程ax^2+bx+c=0 //解一元二次方程ax^2+bx+c=0:从键盘输入a,b,c的值,求x1和x2。如果a=0或b2-4ac&lt;0,输出出错信息。 #include&lt;iostream&gt; #include &lt;cmath&gt; #include&lt;iomanip&gt; using namespace st
1023 0
|
3天前
|
存储 编译器 C++
3.C++类和对象(中)
3.C++类和对象(中)
|
3天前
|
存储 编译器 C语言
【C++语言2】类和对象(上)
【C++语言2】类和对象(上)
|
1天前
|
C语言 C++
C++初阶学习第六弹——探索STL奥秘(一)——标准库中的string类
C++初阶学习第六弹——探索STL奥秘(一)——标准库中的string类
|
1天前
|
C++
C++初阶学习第五弹——类与对象(下)——类与对象的收官战
C++初阶学习第五弹——类与对象(下)——类与对象的收官战
|
1天前
|
编译器 C++
C++初阶学习第四弹——类与对象(中)——刨析类与对象的核心点
C++初阶学习第四弹——类与对象(中)——刨析类与对象的核心点
|
1天前
|
C语言 C++
C++初阶学习第三弹——类与对象(上)——初始类与对象
C++初阶学习第三弹——类与对象(上)——初始类与对象
|
1天前
|
编译器 C++
C++进阶之路:何为运算符重载、赋值运算符重载与前后置++重载(类与对象_中篇)
C++进阶之路:何为运算符重载、赋值运算符重载与前后置++重载(类与对象_中篇)
6 1