简体   繁体   English

无法在控制台中看到c ++程序的输出

[英]unable to see the output of c++ program in the console

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. 我已经在我的Windows 8笔记本电脑上安装了eclipse ide(cdt),并尝试编写一个简单的c程序来检查程序是否执行。

It did not execute and gave the error : binary not found . 它没有执行并给出错误: binary not found

So I did some searching online and realized that my system did not have ac/c++ compiler installed. 所以我做了一些在线搜索,发现我的系统没有安装ac / c ++编译器。
So I installed MinGW and selected the c and c++ compilers during installation. 所以我在安装过程中安装了MinGW并选择了c和c ++编译器。
Then I set the PATH environment variable to C:\\MinGW. 然后我将PATH环境变量设置为C:\\ MinGW。
I reopened eclipse, wrote a simple c program and it worked as expected! 我重新打开了eclipse,写了一个简单的c程序,它按预期工作!

I created a c++ project, wrote a simple piece of code and could not see the output in the console! 我创建了一个c ++项目,写了一段简单的代码,无法在控制台中看到输出!

Here is the code: 这是代码:

#include<iostream>
using namespace std;

int main()
{
    cout<<"sample text";
    return 0;
}

You may simply need to flush the output, using flush or endl . 您可能只需要使用flushendl刷新输出。 Try this: 尝试这个:

cout<<"sample text" << endl;

or 要么

cout<<"sample text" << flush;

Linker (Option) > Add Command (g++ -static-libgcc -static-libstdc++) 链接器(选项)>添加命令(g ++ -static-libgcc -static-libstdc ++)

This is not the right solution. 这不是正确的解决方案。

You have in your path environment variable only c:\\minGW . 您的路径环境变量只有c:\\minGW
But it should be c:\\minGW;c:\\minGW\\bin . 但它应该是c:\\minGW;c:\\minGW\\bin (Set the PATH before open eclipse) (在打开日食之前设置PATH)

Therefore, libstdc++-6.dll needed by the current program, can not be found. 因此,无法找到当前程序所需的libstdc++-6.dll

In eclipse there is no error, but no output in the console !! 在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 ++链接器(选项)>命令(g ++ -static-libgcc -static-libstdc ++)

should be set here : 应该在这里设置:

在此输入图像描述


I know in this case it is not necessary at the end << endl to write. 我知道在这种情况下,没有必要在结尾写<< endl
A good programming style should use << endl : 一个好的编程风格应该使用<< endl

cout << "sample text" << endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM