Eclipse CDT Debug console not displaying program output - eclipse-cdt

I am using Eclipse IDE for C/C++ Developers (Eclipse Ganymede Package - version 3.4.2) on Windows XP with MinGW GCC 4.2.1 and GDB 6.8-3.
I am facing a problem very similar to that mentioned here. A simple hello world program will not print to the console output in the debugger. A run command displays the output correctly. I have checked both gdb output console and the output console.
What are the right settings to get the output in console window of eclipse?

//have you put endl at the end of your output?
int main()
{
cout << "!!!Hello World!!!"; // prints nothing to console ; no endl
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! twice
return 0;
}

Related

C++ console application outputs nothing and won't quit? Codeblocks MinGW GCC

I have a C++ application which is build statically against libcurl. The application compiles perfectly, however when I execute the application it returns nothing on the console. Neither it shows anything when I redirect the output to e.g. > output.txt.
The code is just:
int main(void) {
cout << "Show me" << endl; //Or not... :(
return 0;
}
When executed it just starts the console and keeps black, nothing is happening.

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.
It did not execute and gave the error : binary not found .
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!
I created a c++ project, wrote a simple piece of code and could not see the output in the console!
Here is the code:
#include<iostream>
using namespace std;
int main()
{
cout<<"sample text";
return 0;
}
Linker (Option) > Add Command (g++ -static-libgcc -static-libstdc++)
This is not the right solution.
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)
Therefore, libstdc++-6.dll needed by the current program, can not be found.
In eclipse there is no error, but no output in the console !!
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++)
should be set here :
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;
You may simply need to flush the output, using flush or endl. Try this:
cout<<"sample text" << endl;
or
cout<<"sample text" << flush;

How do I run a C++ program in Xcode 4?

I want to write a C++ program in Xcode on my Mac. I wrote this basic one to test it. When I build, I get a "Build Successful" message.
However, I cannot run it! If I hit Command+R nothing happens. When I go to Project->Run the Run option is disabled.
#include <iostream>
using namespace std;
int main()
{
cout << "helo" << endl;
}
Launch XCode
In the "Choose template" box, pick Mac OS X, then Command Line Tool. Press Next
Give your project a name, select C++ as the type
You should see a new project with main.cpp
press the Run button
At the bottom of the screen, under All Output you should see:
Hello, World!
Program ended with exit code: 0

can't debug small program on eclipse helios cdt using mingw/gdb under windows, console freezes

I've been trying to use Eclipse CDT to do some c++ examples, i can run them just fine with the run command, but whenever i try to Debug, the console window freezes up, I'm able to input, but the program doesn't continue.
When I debug, i get the following output on the console window (no breakpoints, but breaks on main because of default settings):
Hello, world
put your name: 15^running
The continue button is disabled and doesn't do anything when I input something and hit enter. The 15 is a random number, sometimes its 16, 20 etc.
If I run the program under eclipse I get the input prompt just fine:
Hello, world
put your name: test
Hello test
this is the code I try to debug:
#include <iostream>
#include <string>
int main() {
std::cout << "Hello, world" << std::endl;
std::string name;
std::cout << "put your name: ";
std::cin >> name;
std::cout << "Hello " + name << std::endl;
return 0;
}
My path var:
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Java\jdk1.6.0_14\bin;C:\MinGW\bin
Eclipse version: Helios Service Release 2
CDT version: 7.0.2
OS: windows xp
GDB version: GNU gdb (GDB) 7.2
How can I debug this small example under CDT, without issues?
15^running looks as a result record from gdb's Machine Interface. Normally it shouldn't appear in the Eclipse console.
I recommend trying a different Create Process Launcher. It can be changed in the following way:
In Main menu choose "Run" -> "Debug Configurations...".
In the opened "Debug Configurations" window shown below click "Select other..." opposite "Using GDB (DSF) Create Process Launcher".
In the opened "Select Preferred Launcher" window shown below check "Use configuration specific settings", select "Standard Create Process Launcher" in the list below and click OK.
Now go to the Debugger tab in the "Debug Configurations" window, select debugger, e.g. "MinGW gdb" and click Apply.
With the Standard Create Process Launcher I am able to debug your program although "put your name:" is printed only after I type something and hit Enter, because the output stream is not flushed.
Try having a look at this http://www.cprogramming.com/gdbtutorial.html and see if that helps. Like can you press CTRL-C to break?
Also Cannot enter input with gdb. Help! might be a pointer although related to apple.
the following is from the Eclipse website's FAQ:
http://wiki.eclipse.org/CDT/User/FAQ#Eclipse_console_does_not_show_output_on_Windows
Eclipse console does not show output on Windows In Eclipse CDT on
Windows, standard output of the program being run or debugged is fully
buffered, because it is not connected to a Windwos console, but to a
pipe. See bug 173732 for more details. Either add fflush calls after
every printf or add the following lines in the start of the main
function:
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
Seems like an expected bug on windows.

OS X 10.6.4 + Eclipse 3.5 + latest CDT not outputting cout/printf to console

I spend most of my time in Eclipse these days, so I thought I would check out what Eclipse's C++ support was like (I usually use Xcode on Mac and Visual Studio for Windows).
I found the CDT package for Eclipse 3.5, so I installed it.
Everything installed properly and the default C++ "Hello World" project compiled nicely, however for the life of me I can't get any application output piped to the console. I've tried everything, and searched around for solutions, but it seems I'm not the only one. Most have trouble in Windows, but I haven't seen a lot of issues with OS X.
Of course, if I run the compiled output in a bash shell, it displays output properly.
This is how simple the default app is:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
printf("Hello world");
return 0;
}
Any ideas?
Cheers,
Shane
Just tried this in Helios 3.6 and it works. Must be a 3.5 problem.