使用 Windows 和 MinGW 用 Eclipse 编写的 C++ 程序无法将输出显示到控制台视图 [英] C++ program written in Eclipse using Windows and MinGW cannot display output to console view

查看:28
本文介绍了使用 Windows 和 MinGW 用 Eclipse 编写的 C++ 程序无法将输出显示到控制台视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows 7 64 位.

I'm using Windows 7 64bit.

我安装了 eclipse 版本 3.6.2、cdt 和 MinGW.我在 Eclipse 中有一个 C++ 控制台程序,如下所示:

I installed eclipse version 3.6.2, cdt, and MinGW. I have a C++ console program in Eclipse as follows:

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    setbuf(stdout, NULL);

    for (int i = 0; i < 10000000; i++) {
        cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    }
    int val;
    cin >> val;

    return 0;
}

如果我运行这个控制台程序,它应该在 Eclipse 的控制台视图中显示 Hello world,但没有任何显示.

If I run this console program, it should display Hello world to Console View in Eclipse, but nothing displays.

如果我转到调试文件夹并运行 exe,它会打印到控制台.

If I go to the debug folder and run the exe, it does print to the console.

如果我犯了一些语法错误,那么 Eclipse 控制台视图会显示一些东西,例如:

If I make some syntax mistake, then the Eclipse Console View will show something, such as:

**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrchh.o ..srchh.cpp
..srchh.cpp: In function 'int main()':
..srchh.cpp:17:3: error: expected ';' before 'return'
Build error occurred, build is stopped
Time consumed: 255 ms.   

为什么 Eclipse 控制台视图中没有显示任何内容?如何让我的 C++ 控制台程序显示输出?

Why is nothing showing in the Eclipse console view and how can I make my C++ console program display output?

推荐答案

我找到原因了,就因为我用的是64bit eclipse!

I find the reason, just because I'm using 64bit eclipse!

我转向 32 位 eclipse,同样的代码工作正常.

I turn to 32 bit eclipse, the same code works fine.

这篇关于使用 Windows 和 MinGW 用 Eclipse 编写的 C++ 程序无法将输出显示到控制台视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆