在QtCreator中使用cin [英] Using cin in QtCreator

查看:438
本文介绍了在QtCreator中使用cin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For school, we use C++ as the language of choice. I am currently using QtCreator as an IDE, and for its GUI library, it is wonderful. The school is using Visual Studio.

但是,我们编写的大多数程序都使用cin和cout进行输入/输出。 cout可以很好地作为输出,您可以看到它在应用程序输出中所显示的内容,但是没有办法像在控制台上一样提供cin,就像Visual Studio的C ++一样。

However, most of the programs we are writing make use of cin and cout for input/output. cout works fine as output, as you can see what it puts out in the application output, but there is no way to provide to cin as if it were on a console, like Visual Studio uses for its C++.

示例:

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

是否可以像在Visual中那样使用控制台或为cin提供输入Studio?

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

如果有问题,我目前正在运行OS X Leopard。

I am currently running OS X Leopard, if it matters.

推荐答案

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

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".

现在,QtCreator将使用苹果内置的Terminal.app而不是Qt的控制台,从而实现交互式输入。

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

这篇关于在QtCreator中使用cin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆