我刚开始学习C++,我做的主要方法:
#include <iostream>
using namespace std;
int main ()
{
int d;
int n;
cout <<"Enter the denominator: " << endl;
cin >> d;
cout <<"Enter the numerator: " << endl;
cin >> n;
cout <<"The result of operation is: " << endl;
cout << (double)n/d << endl;
cout <<"Done";
return 0;
}
它不产生输出,但如果我删除返回 0。我将产生正确的输出。 C++ 中的 main 方法不应该最终总是返回一个整数吗?
最佳答案
在返回之前尝试 cout.flush();
。
它强制将缓冲数据发送到输出。
关于c++ - 从 main 返回零中断了我的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16533947/