XCode 4 console won't take user input

2019-02-11 01:01发布

问题:

In XCode 4, when I run something like this:

string input;
cout << "Enter command" << endl;
getline(cin, input);
cout << "You entered: " << input << endl;

I see my "Enter command" prompt in the console. But when I place my mouse cursor below it and start typing the cursor doesn't move, and my keystrokes don't show up. It basically behaves like a read-only text box. What am I doing wrong? How can I interact with my program as if it were running in the terminal?

回答1:

Are you pressing Return or Enter at the end of your input line?
For some keyboard the enter and return are on the same button, but if you press "shift" key, while pushing the enter/return button scanf will work.

  • Unshifted must be the Return
  • Shifted must be the Enter.


回答2:

From the site “Xcode Tools Tips”:

When debugging a command line program with Xcode, one problem you may have is figuring out where to input data and read the program's output. If you open the debugging console window by clicking the Console button, you will be able to see your program's output, but you will get an error message any time you try to enter input in the console window. Where do you enter the input your program needs?

The answer is Xcode's standard I/O log. The standard I/O log works similarly to Xcode's run log when you run your program in Xcode without the debugger. Choose Debug > Standard I/O Log to open the log window. Now when you debug your program, you will see its output in the standard I/O log, and you will be able to input any data your program needs to run.

By the way, all I did to find that quote was to highlight your question in the browser, and select “Search” in the browser’s right click menu. It was the fourth hit in Google’s list.

I think, it’s pretty much very often a good idea to google before asking!

Cheers & hth.,



回答3:

In the bottom pane of the debug window[which shows variables and their values], there is a search toolbar and a 3 option box in the upper right hand corner. Click on the middle of the three options which will display the main debug output to the right of the variable pane. The top pane is only for output. The right pane can be used to enter input.

I hope this helps. Sorry that the note is late.