#include<iostream>
using namespace std;
#include<cstdio>
#include"dos.h"
int sum(int &a, int &b)
{
a++;
b++;
return (a)+(b);
}
int main()
{
int a, b;
cout << "Enter a and b";
cout << endl;
cin >> a >> b;
int sum1;
sum1= sum(a, b);
cout << endl << sum1;
cin.get();
cin.get();
return 0;
}
如果我评论任何一个cin.get()
行,程序在完成后关闭(即输出屏幕)。
是因为我必须按两次输入(输入值),最后一个'输入键'在完成程序后关闭程序?
自从我使用visual studio以来我遇到了同样的问题,但是我使用的是这个代码,我没有问题。
cin.clear();
cin.ignore();
cin.get();