Adam Jarvis
Adam Jarvis

Reputation: 181

c++ issues using cout and cin on same line (xcode8)

Using Xcode with c++ I'm trying to create a simple console application. However my usage of cout and cin does not seem to work as I intend it to.

I'm expecting:

Testing: 12
input was 12

edit: i've cut down the code test as much as I can:

#include <iostream>

int main(int argc, const char * argv[]) {
    // insert code here...
    int num;
    std::cout << "Testing: ";
    std::cin >> num;
    std::cout << "input was " << num << std::endl;

    return 0;
}

Sample output:

12
Testing: input was 12
Program ended with exit code: 0

Is there something I'm missing here?

Upvotes: 4

Views: 528

Answers (1)

Rama
Rama

Reputation: 3305

Apparently is a specific problem with C++ streams, in Xcode debugger, Debug build.

Try this:
1. Project -> Edit Active Target ...
2. Search for "preprocessor" in Build
3. Delete the values:
Preprocessor Macros = _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1

I found a similar issue but for Xcode 3.2.1 and C++ string fails!

You can try also this workaround:
Paste these lines at the very beginning of your program (before any #include statements):

#define _GLIBCXX_FULLY_DYNAMIC_STRING 1
#undef _GLIBCXX_DEBUG
#undef _GLIBCXX_DEBUG_PEDANTIC

Upvotes: 1

Related Questions