gpt4 book ai didi

c++ - 在 QtCreator 中使用 cin

转载 作者:可可西里 更新时间:2023-11-01 16:39:44 25 4
gpt4 key购买 nike

对于学校,我们使用 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;
}

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

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

最佳答案

在 Preferences 的 Environment 部分下,将“Terminal”选项设置为 /Applications/Utilities/Terminal.app,正如 Alex Martelli 所指出的。

然后,在“项目”选项卡中的“运行设置”下,选中标记为“在终端中运行”的框。

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

关于c++ - 在 QtCreator 中使用 cin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1484950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com