gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:44:59 26 4
gpt4 key购买 nike

#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();

关于c++ - 在这种情况下如何防止 C++ 输出/控制台表单关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52140561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com