• 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;
    }
  • 相关阅读:
    sss
    sss
    maven tomcat jstl 异常
    第1章 预备知识
    第2章 存储管理
    第8章 虚拟机字节码执行引擎
    第23章 Spring MVC初体验
    第1章 预备知识
    第5章 Java中的锁
    第13章 线程安全与锁优化
  • 原文地址:https://www.cnblogs.com/mohu/p/8953452.html
Copyright © 2020-2023  润新知