简体   繁体   English

错误消息“iostream:没有这样的文件或目录”

[英]Error message "iostream: no such file or directory"

I am working with Qt Creator on Windows Vista .我正在Windows Vista上使用Qt Creator I am trying to compile very simple ".cpp" code that includes the standard C++ library "iostream", like this:我正在尝试编译包含标准 C++ 库“iostream”的非常简单的“.cpp”代码,如下所示:

#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 ).当 Qt 突出显示库并承认我( iostream:没有这样的文件或目录)时,它就出现了。

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.几天前它运行良好,但后来我安装了Visual Studio 2012 Express ,然后我将其卸载,因为令人惊讶的是,它不适用于 Windows Vista。 Immediately after the removal of Visual Studio 2012, C++ libraries are not seen by Qt Creator any more.在删除 Visual Studio 2012 之后,Qt Creator 不再看到 C++ 库。

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!请注意,我仍然可以通过命令行控制台编译和运行我之前编写的代码,这意味着 C++ 库并没有随着 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:此外,我以前的所有代码(在使用相同 Qt 创建的旧项目中)都没有这样的问题(即 Qt 识别并查看标准库),我仍然可以使用 Qt Creator 正常编译和运行它们,即使当我在这些旧项目中创建了一个新的“.cpp”文件:

在此处输入图像描述

However, when I create a new ".cpp" file within a totally new project, libraries disappear and a link is missing:但是,当我在一个全新的项目中创建一个新的“.cpp”文件时,库消失并且缺少链接:

在此处输入图像描述

(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.) (我不想习惯每次在编译器遇到类似问题时都重新安装 Qt,我想首先了解为什么会发生这种情况。)

So, what exactly is Qt looking for (or where I should be looking at)?那么,Qt 到底在寻找什么(或者我应该在哪里寻找)?

You don't need to reinstall Qt Creator.您不需要重新安装 Qt Creator。 If you want to use it for running C++ source code, you should first create a project file.如果你想用它来运行 C++ 源代码,你应该首先创建一个项目文件。 Do as follows:执行以下操作:

Menu FileNew file or projectNon-Qt projectPlain C++ application .菜单文件新文件或项目非 Qt 项目普通 C++ 应用程序

So that you create a .pro file.这样您就可以创建一个 .pro 文件。 Then Qt Creator will be able to find library files <iostream> and the like.然后Qt Creator就能找到<iostream>之类的库文件。 See Qt Creator can't find headers (says: "No such file or directory") for a detailed explanation.有关详细说明,请参阅Qt Creator 找不到标头(说:“没有这样的文件或目录”)

First open your project file (".pro") in Qt Creator and add the following line:首先在 Qt Creator 中打开您的项目文件(“.pro”)并添加以下行:

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

Then try to use #include <iostream> in your code.然后尝试在您的代码中使用#include <iostream>

For me, INCLUDEPATH is /usr/include/c++/4.7.3/ .对我来说, INCLUDEPATH/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.这个问题发生在我们刚刚安装 Qt 之后,使用的安装程序应该与 .NET 编译器一起使用。

The .NET installation was not complete: C++ development feature was not installed. .NET 安装未完成:未安装 C++ 开发功能。 We completed the .NET installation, restarted Qt and the problem was off: Qt automatically detected the newly installed compiler program and <iostream> was found.我们完成了.NET的安装,重启Qt,问题就解决了:Qt自动检测到新安装的编译程序,发现<iostream>。

Note that with some machines, we needed to start Qt as administrator in order to make this work.请注意,对于某些机器,我们需要以管理员身份启动 Qt 才能完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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