c++ - 从 main 返回零中断了我的程序

标签 c++

我刚开始学习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/

相关文章:

c++ - 如何将#define-constants 转移到另一个 C++ 项目?

c++ - 为什么 const 引用会延长右值的生命周期?

c++ - 从奇怪的版本字符串中提取数字

c++ - fetch_add(0, memory_order_relaxed/release) 到 mfence + mov 的转换是否合法?

c++ - 如何获取 UNo 中引用的地址?

c++ - Qt 中的非类方法(使用 qtcreator)未解析的外部符号

c++ - 访问 'padded'字节是不是UB?

C++虚方法

c++ - C/C++ 中的 Retro、Lomo、Vignette 滤镜?

c++ - 如何制作不依赖于 .so 文件的可执行二进制文件