简体   繁体   中英

Pure C++ build with QtCreator

At the moment I am using QtCreator 2.8.1 based on Qt 5.1.1 under Ubuntu Linux. I do both, Qt Development and coding pure C++ projects. Because I don't want to install a second heavyweight IDE like Eclipse for latter I'd like to use QtCreator for that.

Up to now I created a new C++ Project (without Qt) by clicking on File->New->C/C++ Project (without Qt)->C++-Project . So now coding works fine. But with my first build I discovered a huge problem with my main.cpp

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    ifstream infile("file1.in");
    string line;

    while(infile >> line) {
        cout << line << endl;
    }

    cout << "hello world" << endl;

return 0;
}

When I run this within QtCreator I see only "hello world" on the console, but nothing more (file1.in contains more than 20 lines of raw text). Now the strange thing. After compiling this with a little g++ main.cpp I see all my 20 lines of text and "hello world".

Does anybody have a clue why this happens? I thought I have to change the compiler in QtCreator, but this attempt wasn't successfully.

QtCreator by default use shadow builds, it means you executable will be build in separated folder. In your code you use relativ path to the file:

ifstream infile("file1.in");

simply change it fullpath or make sure your file1.in exist in the shadow build folder for your project.

ifstream infile("C:\\file1.in");

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