Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Cannot give input through the console
Cannot give input through the console [message #676752] Mon, 06 June 2011 12:31 Go to next message
Santosh  is currently offline Santosh Friend
Messages: 2
Registered: June 2011
Junior Member
Hi guys,

I have a simple 'Hello World' program here and I am trying to read the user input:

#include <iostream>

using namespace std;

int main(void) {
	int i;
	cout << "Hello World!!!" << endl;
	cin >> i;
	cout << "hello 2";
	return 0;
}


I can compile and build the project but when I debug it I don't know why but the control stops at the main() function. I have to click the "Resume" button on the Debug window in order to get it moving. After that I can see the message "Hello World!!!" in the console and it stops for user input. When I type numbers on console I can see the numbers being typed in green color but when I press the 'Enter' key the cursor just goes to the next line in the console. The program doesn't continue and I don't see the second message "hello 2" printed. No matter what I do the program doesn't continue. When I browse to the .exe file and execute it manually it works as expected.

I am new to Eclipse CDT and may be doing something wrong here. Please help me solve this issue.

My Specs:
Eclipse version: Eclipse Helios CDT Service Release 2
Build id: 20110218-0911
Platform: Windows 7 x64
Toolchain: MinGW
GCC Version: 4.5.2
G++ Version: 4.5.2
GDB Version: 7.2
GNU Make Version: 3.81

[Updated on: Mon, 06 June 2011 12:31]

Report message to a moderator

Re: Cannot give input through the console [message #677071 is a reply to message #676752] Tue, 07 June 2011 13:37 Go to previous messageGo to next message
Marc Khouzam is currently offline Marc KhouzamFriend
Messages: 357
Registered: July 2009
Senior Member
Stopping on main is the default CDT Debug behavior. You can disable that by going to Run->Debug Configurations..., then select your launch and choose the Debugger tab. There is a "Stop on startup" check mark you can disable.

In the next CDT release, you can configure this globally to always have it off: http://wiki.eclipse.org/CDT/User/NewIn80#New_set_of_preferences

As for the console it may be a Windows issue, the console there is lacking. One solution that could help is to add a gdbinit file that contains
set new-console one
This should pop-up a new window to deal with input/output.

Marc
Re: Cannot give input through the console [message #677202 is a reply to message #677071] Tue, 07 June 2011 20:17 Go to previous messageGo to next message
Santosh  is currently offline Santosh Friend
Messages: 2
Registered: June 2011
Junior Member
Thanks Marc for the reply. There is a typo in your gdb command. It should be
set new-console on

I tried your solution following this[www.dirac[dot]org/linux/gdb/03-Initialization,_Listing,_And_Running.php] guide. But it didn't work. May be the gdb didn't read the .gdbinit file even though I set it up correctly. Then I set the GDB Command file in the same Debug Configurations window as you suggested before, i.e: Run -> Debug Configurations... -> <Selected my Application on the LHS pane> -> Debugger tab on the RHS -> GDB Command File

Now I see an external gdb console every time I debug my application. This is not what I expected because its quite bothersome to switch between the windows every debug step but it works nonetheless.
Re: Cannot give input through the console [message #677207 is a reply to message #677202] Tue, 07 June 2011 20:28 Go to previous message
Marc Khouzam is currently offline Marc KhouzamFriend
Messages: 357
Registered: July 2009
Senior Member
Sorry about the typo.

yes, you have to specify the gdbinit file in the launch as you did.

It is not very nice to have the extra window, but you could only enable that for programs that use cin.

I haven't actually tried cin on windows (I have a linux machine), so I don't know if it is a limitation, or if there is a bug in Eclipse.

Marc
Previous Topic:tweaking the indexer
Next Topic:Qt-Integration Problem
Goto Forum:
  


Current Time: Thu Apr 25 17:15:12 GMT 2024

Powered by FUDForum. Page generated in 0.03441 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top