在QtCreator中使用cin

Aus*_*yde 9 c++ cin qt-creator

对于学校,我们使用C++作为首选语言.我目前正在使用QtCreator作为IDE,对于它的GUI库,它非常棒.学校正在使用Visual Studio.

但是,我们编写的大多数程序都使用cin和cout进行输入/输出.cout可以正常输出,因为你可以看到它在应用程序输出中输出的内容,但是没有办法提供给cin,好像它在控制台上,就像Visual Studio用于它的C++一样.

一个例子:

#include <iostream>
#include <string>
using namespace std;
int main() {
    string name;
    cout << "Enter name: ";
    cin >> name;
    cout << "Your name is " << name << endl;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在Visual Studio中使用控制台或提供cin输入?

我目前正在运行OS X Leopard,如果重要的话.

Aus*_*yde 8

在"首选项"中的"环境"部分下,将"终端"选项设置为/Applications/Utilities/Terminal.app,如Alex Martelli所指出的那样.

然后,在"项目"选项卡的"运行设置"下,选中"在终端中运行"框.

现在,QtCreator将使用Apple的内置Terminal.app而不是Qt的控制台,允许交互式输入.