开发者

Run C++ code in Qt Creator on Ubuntu

开发者 https://www.devze.com 2023-02-15 02:25 出处:网络
I must write some C++ on Ubuntu Linux. After many searches I found Qt Creator IDE and G++ compiler. So, the problem is: how to run a C++ program and show console black window? For example, how can I g

I must write some C++ on Ubuntu Linux. After many searches I found Qt Creator IDE and G++ compiler. So, the problem is: how to run a C++ program and show console black window? For example, how can I get result from this code :

#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] << " ";
}

I am very in a hurry and I will be very thankful for your answer.


I changed code to this:

#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] << " " &l开发者_Python百科t;< flush; 
//    return a.exec();
}

but still isn't working. I enter each number in one line, is it correct? How can I enter data for array in true way?


Well... there is the play button that will run your application. On lowest-right part of QTCreator, there is a tab "3 application output" that will show you the output.

If you want to run the application in a console without QtCreator, go to the folder where you have your source code. There should be the executable that you can run with

./excutable_name


There is a checkbox "Run in terminal" in the run configurations (left rim, "Projects" tab, "Run", "Run Configuration"). If you check that you get an external terminal opened, by default xterm. You can configure another terminal in the lobal setting ("Tools", "Options", "Environment", "General", "System")

0

精彩评论

暂无评论...
验证码 换一张
取 消