The following code works fine when it's run but there's an issue when it's run in debug mode using Eclipse, it does not wait for input and instead just keeps going and some seemingly random value is printed to the console. It also won't stop at a breakpoint.
int main() {
int N, Q, maxSize;
cout <<"Enter a number"<<endl;
int test;
cin >> test;
cout << test <<endl;
}
Update
From CDT 9.4 (Eclipse Oxygen.2) there is now a checkbox in the launch configuration to do this with one-click. See https://wiki.eclipse.org/CDT/User/NewIn94#Debug
Original answer
The problem here is there are two readers on the same stdin channel. When you do cin
Eclipse CDT is also trying to read stdin for the GDB-MI communication.
Fortunately there is a workaround, you can have GDB create a separate console for the program that is running. That means no sharing of the handles.
To do so create a .gdbinit
file in the root of the project with these contents:
set new-console on
and debug your console app in Eclipse to your heart's content:
More Info
You can set the gdbinit file to use for your Debug Configuration in the Debugger tab. Set the GDB Command file to the name of the file you have created.
You can set the default GDB Command file to use for newly created Debug Configurations by editing the preference in C/C++ -> Debug -> GDB page:
Eclipse CDT does not use the .gdbinit in your home directory. This is on purpose because the .gdbinit that is there is normally set up for CLI debugging and can easily interfere with the MI inteface needed for Eclipse to communicate with GDB properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With