版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zaishuiyifangxym/article/details/82933563
使用 cin >> Variable name;//从键盘输入字符
如果使用 一个 cin.get(); 在输入字符后,屏幕窗口会消失。
这时候,需要两个 cin.get(); 语句
如下程序所示:
#include<iostream>
int main()
{
using namespace std;
int carrots;
cout << "How many carrots do you have?" << endl;
cin >> carrots; // C== input 从窗口中获取输入
cout << "Here are two more. ";
carrots = carrots + 2;
cout << "Now you have " << carrots << " carrots."<< endl;
cin.get(); //读取输入 屏幕显示,按Enter键读取输入
cin.get(); //程序暂停 屏幕显示,直到按Enter键
return 0;
}
运行结果: