cpp - 输入输出

c语言面向过程

c++支持面向过程+支持面向对象

#include <iostream>

using namespace std;

int main()
{
    int a;
    cout << "请输入a的值:" << endl;
    cin  >> a;
    cout << "a的值为:" << a << endl;
    return 0;
}

挺方便的。不用关注占位符。不用关注数据类型。

endl 相当于回车。

或者下面这样使用,

#include <iostream>

// using namespace std; // 张家-小强 李家-小强
int main()
{
    int a;
    std::cout << "请输入a的值:" << std::endl;
    std::cin  >> a;
    std::cout << "a的值为:" << a << std::endl;
    return 0;
}

或者

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    int a;
    cout << "请输入a的值:" << endl;
    cin  >> a;
    cout << "a的值为:" << a << endl;
    return 0;
}

相关文章:

  • 2021-12-04
猜你喜欢
  • 2021-11-05
  • 2021-08-03
  • 2021-06-08
  • 2021-04-29
  • 2021-12-15
  • 2021-12-09
相关资源
相似解决方案