在这种情况下如何防止C ++输出/控制台表单关闭

问题描述 投票:1回答:1
#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()行,程序在完成后关闭(即输出屏幕)。

是因为我必须按两次输入(输入值),最后一个'输入键'在完成程序后关闭程序?

c++ runtime cin
1个回答
0
投票

自从我使用visual studio以来我遇到了同样的问题,但是我使用的是这个代码,我没有问题。

cin.clear();
cin.ignore();
cin.get();
© www.soinside.com 2019 - 2024. All rights reserved.