但是,如何从终端获得用户输入?或者,如何将文件中的数据输入到程序中或将结果写入文件?

 cin

标准库提供输出到终端的功能。同样地,库还提供从终端读入数据的功能。

这段代码演示了如何使用 cin:

# include <iostream>
# include <vector>

using namespace std;

int main() {

    int integerone; 
    int integertwo;

    //声明数组并赋值
    cout << "Enter an integer between 1 and 100" << endl;
    cin >> integerone;

    cout << "Enter another integer between 1 and 100" << endl;
    cin >> integertwo;

    //输出差
    cout << "The difference between your two numbers is: ";
    cout << integerone - integertwo << endl;


    return 0;
}

 

相关文章:

  • 2021-05-31
  • 2022-02-03
  • 2021-12-10
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-24
  • 2021-09-06
  • 2021-11-28
  • 2021-08-08
  • 2021-06-17
  • 2021-08-23
  • 2022-12-23
相关资源
相似解决方案