0

我刚开始学习 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 方法最终不应该总是返回一个整数吗?

4

2 回答 2

1

cout.flush();在返回之前尝试。它强制将缓冲的数据发送到输出。

于 2013-05-14T02:00:38.280 回答
0

我浏览了您的代码,一切似乎都是正确的。当我运行它时,它工作正常。如果您还没有解决它,请尝试将您的代码剪切并粘贴到一个新项目中。我知道这听起来很愚蠢,但它应该工作。

我希望这能帮到您。

于 2013-05-14T03:12:35.113 回答