简体   繁体   中英

Run C++ code in Qt Creator on Ubuntu

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] << " " << 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM