Cannot enter input with gdb. Help!

2 Solutions Collect From Internet About “Cannot enter input with gdb. Help!”

I guess there is a bug in GCC related to the usage of std::cin and setting/unsetting breakpoints. I did a minimal example:

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[])
    string option = "x";
    while (option != "q")
        cout << endl 
        << "0 = Stop" << endl
        << "1 = Play" << endl
        << "q = Quit" << endl;

        getline(cin, option);
        cout << "You choosed " << option << endl;

This code works perfectly until you set or activate a breakpoint (at least using the XCode wrapper). From then on stdin buffer is broken and every getline() retrieves the last input even though you don’t type a key, entering a endless loop.

I don’t know how to work arround it… 🙁

Programming C++ using XCode can sometimes be a pain. Try including your source code so that we can see what’s wrong.