无法在我的程序中获得所需的输出

时间:2015-03-22 01:57:57

标签: c++

我是c++的新手。

  #include <iostream>
    using std::cout;
    using std::endl;
    using namespace std;
    int main()
    {
        int a = 0;
        int b = 10;
        cout << "Enter first number \n";
        cin >> a;
        if (a < 10)
        {
            cout << "Less";
        }
    }

现在,当我输入5时,没有任何事情发生,控制台退出。我认为它应该显示“更少”但它没有。为什么呢?

1 个答案:

答案 0 :(得分:2)

这是因为您正在使用某种IDE,并且通常在IDE中它们会显示一个包含输出的控制台盒,并且该控制台在程序完成后会消失。

正在显示,但控制台窗口退出的速度太快,您无法看到它。

您可以做的是在最后添加几行,例如:

#include <iostream>
#include <string>
using std::cout;
using std::endl;
using namespace std;
int main()
{
    int a = 0;
    int b = 10;
    cout << "Enter first number \n";
    cin >> a;
    if (a < 10)
    {
        cout << "Less";
    }

    std::string pause;
    cin >> pause;
}
相关问题