c++qt-creatorcin

How to provide input to a console application using cin in Qt Creator


On OS X Leopard, I am using Qt Creator as an IDE to work with C++.

cout works fine as output, however, there is no way to provide input to cin as if it were on a console, like Visual Studio does for C++.

An example:

#include <iostream>
#include <string>

using namespace std;

int main() {
    string name;
    cout << "Enter name: ";
    cin >> name;
    cout << "Your name is " << name << endl;
}

Is there a way to use a console or provide input to cin like in Visual Studio?


Solution

  • In Preferences, under the Environment section, set the "Terminal" option to /Applications/Utilities/Terminal.app, as pointed out by Alex Martelli.

    Then, in the Projects tab, under Run Settings, check the box marked "Run in Terminal".

    Now, QtCreator will use Apple's built-in Terminal.app instead of Qt's console, allowing for interactive input.