我必须在 Ubuntu Linux 上写一些 C++。经过多次搜索,我找到了 Qt Creator IDE 和 G++ 编译器。所以,问题是:如何运行 C++ 程序并显示控制台黑窗口?例如,我怎样才能从这段代码中得到结果:
#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;
int main()
{
cout << "Hello";
int a[5];
cout << "Enter 5 numbers";
for(int i=0;i<5;i++)
cin >> a[i];
for(int i=0;i<5;i++)
cout << a[i] << " ";
}
我很着急,非常感谢您的回答。
我把代码改成这样:
#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;
int main()
{
// QCoreApplication a(argc, argv);
cout<<"Hello";
int a[5];
cout<<"Enter 5 numbers";
for(int i=0;i<5;i++)
cin>>a[i];
for(int i=0;i<5;i++)
cout << a[i] << " " << flush;
// return a.exec();
}
但还是不行。我在一行中输入每个数字,是否正确?如何以真正的方式为数组输入数据?
最佳答案
好吧...有一个运行您的应用程序的播放按钮。在 QTCreator 的右下角,有一个选项卡“3 application output”,它会显示输出。
如果您想在没有 QtCreator 的情况下在控制台中运行该应用程序,请转到您拥有源代码的文件夹。应该有可以运行的可执行文件
./excutable_name
关于c++ - 在 Ubuntu 上的 Qt Creator 中运行 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5220332/