A problem with Xcode

I have been through this over and over and compared with the example on GitHub but I’m having a problem. When I compile and run it waits for my input (no prompt) and then after I’ve typed something it asks me to enter my guess and prints the guess all on one line:

Here is my code - any idea what I’ve done wrong or is it just an Xcode quirk?

#include <iostream>
#include <string>

using namespace std;

void PrintIntro();
void PlayGame();
string GetGuess();
bool AskToPlayAgain();

// The entry point of our application

int main()
    return 0; // exit the application

// introduce the game
void PrintIntro()
    constexpr int WORD_LENGTH = 9;
    cout << "Welcome to Bulls and Cows, a fun word game.\n";
    cout << "Can you guess the " << WORD_LENGTH;
    cout << " letter isogram I'm thinking of?\n";
    cout << endl;

void PlayGame()
    // loop for the number of turns asking for guesses
    constexpr int NUMBER_OF_TURNS = 5;
    for (int count = 1; count <= NUMBER_OF_TURNS; count++)
        string Guess = GetGuess();
        cout << "Your guess was: " << Guess << endl;
        cout << endl;

string GetGuess()
    // get a guess from the player
    cout << "Enter your guess: ";
    string Guess = "";
    getline (cin, Guess);
    return Guess;

bool AskToPlayAgain ()
    cout << "Do you want to play again? ";
    string Response = "";
    getline (cin, Response);
    cout << "Is it y? " << (Response[0] == 'y');
    cout << endl;
    return false;

I edited the “scheme” to use Terminal as the Console rather than Xcode and that works as it should (although it’s pretty ugly). Does Xcode just not work well for this kind of thing?

I have just had the same problem, after updating my program to XCode 8.3. It used to work fine. The problem seems to be that you need \n or endl at the end of your output, or nothing is displayed. This means you cannot get the input on the same line as the message. I think this could be a bug in XCode 8.3. I have not found a workaround for this yet I would be interested in an XCode expert opinion

Just came here to say that I’m also having the same problem with Xcode 8.3.

Is this related? http://stackoverflow.com/questions/43102289/c-issues-using-cout-and-cin-on-same-line-xcode8

Couldn’t get that to work anyway, using Terminal for now.

I have submitted an XCode bug report (31352015)

anyone have a solution? I’m experiencing the same problem with xcode (ver 8.3.1).

Privacy & Terms