无法在控制台中看到c ++程序的输出 [英] unable to see the output of c++ program in the console
问题描述
我已经在我的Windows 8笔记本电脑上安装了eclipse ide(cdt),并尝试编写一个简单的c程序来检查程序是否执行。
I have installed the eclipse ide(cdt) on my windows 8 laptop and tried writing a simple c program to check whether the program executes.
它没有执行并给出错误:二进制未找到
。
It did not execute and gave the error : binary not found
.
所以我做了一些在线搜索,意识到我的系统没有安装了ac / c ++编译器。
所以我安装了MinGW,并在安装过程中选择了c和c ++编译器。
然后我将PATH环境变量设置为C:\MinGW。 br>
我重新打开eclipse,写了一个简单的c程序,并按预期工作!
So I did some searching online and realized that my system did not have a c/c++ compiler installed.
So I installed MinGW and selected the c and c++ compilers during installation.
Then I set the PATH environment variable to C:\MinGW.
I reopened eclipse, wrote a simple c program and it worked as expected!
我创建了一个c ++项目,写了一个简单的代码段,没有看到控制台中的输出!
I created a c++ project, wrote a simple piece of code and could not see the output in the console!
这是代码:
#include<iostream>
using namespace std;
int main()
{
cout<<"sample text";
return 0;
}
推荐答案
)>添加命令(g ++ -static-libgcc -static-libstdc ++)
这不是正确的解决方案。
This is not the right solution.
您的路径环境变量只有 c:\minGW
。
但它应该是 c:\minGW; c:\minGW\bin
。 (在打开eclipse之前设置PATH)
You have in your path environment variable only c:\minGW
.
But it should be c:\minGW;c:\minGW\bin
. (Set the PATH before open eclipse)
因此,当前程序需要 libstdc ++ - 6.dll
没有找到。
Therefore, libstdc++-6.dll
needed by the current program, can not be found.
在eclipse中没有错误,但在控制台中没有输出!!
将其编译到程序中可能被视为一个技巧,但仅适用于标准库。
It to compile into the program may be regarded as a trick, but will only work for the standard libs .
您的链接器标志不应该如下设置:
your linker flags should not be set like :
- > MinGW C ++ Linker(Option)> Command(g ++ -static -libgcc -static-libstdc ++)
--> MinGW C++ Linker (Option) > Command (g++ -static-libgcc -static-libstdc++)
应该设置在这里:
我知道在这种情况下,最后没有必要<< endl
写入。
一个好的编程风格应该使用<< endl
:
I know in this case it is not necessary at the end << endl
to write.
A good programming style should use << endl
:
cout << "sample text" << endl;
这篇关于无法在控制台中看到c ++程序的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!