简体   繁体   中英

Error message "iostream: no such file or directory"

I am working with Qt Creator on Windows Vista . I am trying to compile very simple ".cpp" code that includes the standard C++ library "iostream", like this:

#include <iostream>
using namespace std;

int main(){
    cout << "thanks";
    return 0;
}

The problem comes even before compiling the code. It comes when Qt highlights the library and acknowledge me that ( iostream: no such file or directory ).

It was working fine a couple of days ago, but then I installed Visual Studio 2012 Express which I then uninstalled because, surprisingly, it does not work with Windows Vista. Immediately after the removal of Visual Studio 2012, C++ libraries are not seen by Qt Creator any more.

Note that I can still compile and run my previous written code by a command-line console, which means C++ libraries haven't been removed with the removal of Visual Studio 2012! In addition, all my previous code (within old projects which were created using the same Qt) has no such problem (ie, Qt identifies and sees the standard libraries), and I can still compile and run them normally using Qt Creator, even when I create a new ".cpp" file within those old projects:

在此处输入图像描述

However, when I create a new ".cpp" file within a totally new project, libraries disappear and a link is missing:

在此处输入图像描述

(I don't want to get used to reinstall Qt each time I have a similar problem with the compiler, I would like to understand why this is happening in the first place.)

So, what exactly is Qt looking for (or where I should be looking at)?

You don't need to reinstall Qt Creator. If you want to use it for running C++ source code, you should first create a project file. Do as follows:

Menu FileNew file or projectNon-Qt projectPlain C++ application .

So that you create a .pro file. Then Qt Creator will be able to find library files <iostream> and the like. See Qt Creator can't find headers (says: "No such file or directory") for a detailed explanation.

First open your project file (".pro") in Qt Creator and add the following line:

INCLUDEPATH += /usr/include/c++/{gcc_version}/

Then try to use #include <iostream> in your code.

For me, INCLUDEPATH is /usr/include/c++/4.7.3/ .

This problem occurred to us just after installation of Qt, using an installer of a version supposed to be used with the .NET compiler.

The .NET installation was not complete: C++ development feature was not installed. We completed the .NET installation, restarted Qt and the problem was off: Qt automatically detected the newly installed compiler program and <iostream> was found.

Note that with some machines, we needed to start Qt as administrator in order to make this work.

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