C++ not showing cout in Xcode console but runs perfectly in Terminal

后端 未结 2 605
梦谈多话
梦谈多话 2020-12-06 15:37

Basically i am running a simple program in Xcode Version 8.3 (8E162)

#include 
using namespace std;
int main() {
    int a;   
         


        
相关标签:
2条回答
  • 2020-12-06 15:41

    You already solved your problem yourself: std::cout uses buffered output and should always be flushed. You can achieve this by either using std::cout << "What is your age? << std::flush, by using std::cout.flush() or by adding a line break like std::endl which flushes implicitly.

    A complete solution could look like this:

    #include <iostream>
    
    using namespace std;
    
    int main() {
        int a;   
        cout << "What is your age: " << flush;
        cin >> a;
        cout << "My age is " << a << endl;
        return 0;
    }
    
    0 讨论(0)
  • 2020-12-06 15:50

    By doing some research, there seems to be bug on cin and cout stream on Xcode Version 8.3 Build 8E162 released on Mar 27, 2017. Degrading to Xcode Version 8.2.1 works like a charm.

    0 讨论(0)
提交回复
热议问题