c++学习4 -- 输入输出

cout 输出

#include <iostream>
using namespace std;

int main()
{
    cout << "hello c++" << ' ' << 12; //可以连续输出
    cout << 'a' << 12.123 << endl;//自动识别类型

    int a = 12;
    char b = 'b';
    float f = 123.12f;
    cout << a << b << f;

    system("pause");
    return 0;
}

endl 换行符

#include <iostream>
using namespace std;

int main()
{
    cout << "hello c++" << endl; //换行,并且清空缓冲区

    cout << "hello c++" << '\n'; // \n 换行符

    system("pause");
    return 0;
}

// endl 多了一个刷新缓冲区的操作,这个操作,会使缓冲的字符立刻显示在屏幕上。
// \n 则不保证这一点,也就是说在一些操作系统上,\n的显示会慢一点,常用的这些系统不会遮掩不过,与endl没什么区别
// 比如键盘输入的字符,

cin 输入

#include <iostream>
using namespace std;

int main()
{
    char c;
    int a;
    double d;

    cin >> c;
    cout << c;
    
    cin >> c >> a >> d;
    cout << c << ' ' << a << ' ' << d << endl;

    system("pause");

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mohu/p/8953452.html