应用程序在显示最终输出之前结束
Application ends before displaying final output
我正在做一个用于培训的控制台应用程序。当我调试下面的代码时,它会在显示之前关闭自己
std::cout << e << std::endl;
如果我将整数e及其输出移动到std::cout << "Enter a number:";
之前,它可以正常工作,但当如下所示时,只有它的输入可以工作,控制台会自行关闭。
#include "stdafx.h"
#include <iostream>
int raisemath()
{
std::cout << "Enter an integer: "; // ask user for an integer
int a; // allocate a variable to hold the user input
std::cin >> a; // get user input from console and store in variable a
return a; // return this value to the function's caller (main)
}
int main()
{
int number;
std::cout << "Enter a number:";
std::cin >> number;
std::cout << "You entered " << number << std::endl;
int e = raisemath();
std::cout << e << std::endl;
return 0;
}
我想知道为什么?
在最后一个std::cout
之后,没有任何东西可以阻止控制台关闭
当您更改std::cout
的位置时,后面会有一条input语句。因此控制台会等待输入继续执行。
通过在最后一条返回语句处添加断点或在返回语句之前添加空白输入,可以很容易地防止控制台关闭。
您可能还想检查调试器设置,看看是否选中了"调试停止时自动关闭控制台"。(位于"工具">"选项">"调试"中)
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 在结束运行之前获取 c++ 中的 shell 命令输出
- 程序不会在必须时结束并显示输出
- 带有文件结束函数的 while 循环重复输出文件中的最后一个数字两次
- 创建以不良输出结束
- 应用程序在显示最终输出之前结束
- 程序在输出后不会结束
- 如何确定输出流链是否已结束?
- 如何删除此代码输出的结束空格
- boost属性树xml编写器输出没有结束
- 数组循环在循环结束后输出垃圾
- 插入标准::结束后输出奇怪
- 编译后的c++输出文件在程序结束时显示随机字符
- std::cout输出直到程序结束才打印
- 输出一个整数数组以垃圾结束