从main返回0会中断我的程序

Returning zero from main breaks my program

本文关键字:中断 我的 程序 main 返回      更新时间:2023-10-16

我刚开始学习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();。它强制将缓冲的数据发送到输出。

我看了你的代码,一切似乎都是正确的。当我运行它时,它工作得很好。如果你还没有解决它,试着把你的代码放到一个新项目中。我知道这听起来很愚蠢,但它应该工作。