C++ VS 2010 错误 - 无法打开文件“iostream”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4594292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:52:18  来源:igfitidea点击:

VS 2010 error - cannot open file "iostream"

c++visual-studio-2010compilationwindows-xp-sp3

提问by cpx

I've just migrated from VS2005 to VS2010 and it fails to compile a simple program.

我刚刚从 VS2005 迁移到 VS2010,它无法编译一个简单的程序。

#include <iostream>
using std::cout;
using std::endl;

int main()
{
    cout << "Hello Visual Studio 2010 :)" << endl;
}

Errors -

错误 -

1  error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified.
2  IntelliSense: cannot open source file "iostream"
3  IntelliSense: name followed by '::' must be a class or namespace name
4  IntelliSense: name followed by '::' must be a class or namespace name
5  IntelliSense: identifier "cout" is undefined
6  IntelliSense: identifier "endl" is undefined

PS: I'm completely new to using VS2010 but have experience in VS 2005.

PS:我对使用 VS2010 完全陌生,但有 VS 2005 的经验。

Here are lists of directories that I added from VS2005 to VS2010 under 'user property sheet'

以下是我在“用户属性表”下从 VS2005 添加到 VS2010 的目录列表

Executable -

可执行 -

$(VCInstallDir)bin; $(VSInstallDir)Common7\Tools\bin; $(VSInstallDir)Common7\tools; $(VSInstallDir)Common7\ide; $(VSInstallDir); $(VSInstallDir)\SDK\v2.0\bin

Include -

包括 -

$(VCInstallDir)include; $(VCInstallDir)atlmfc\include; $(FrameworkSDKDir)include

Library -

图书馆 -

$(VCInstallDir)lib; $(VCInstallDir)atlmfc\lib; $(VCInstallDir)atlmfc\lib\i386; $(FrameworkSDKDir)lib; $(VSInstallDir); $(VSInstallDir)lib

Source -

来源 -

$(VCInstallDir)atlmfc\src\mfc; $(VCInstallDir)atlmfc\src\mfcm; $(VCInstallDir)atlmfc\src\atl; $(VCInstallDir)crt\src

采纳答案by Ralf

I've run into the same issue on a couple of different machines where there were other versions of VS (2005, 2008) already installed. I ended up also getting all sorts of strange errors.

我在已经安装了其他版本的 VS(2005、2008)的几台不同机器上遇到了同样的问题。我最终也收到了各种奇怪的错误。

I found the following trick worked for me, maybe it will work in your case too: - Open a new instance of VS2010 - Create new console application with the def settings. - Try compile: there should be some errors - Open the "Property Manager" - Bring up the Microsoft.Cpp.Win32.user property sheet of the project - Click on VC++ Directories - Click on the "Executable Directories" field. That should display a drop down, click on the drop down and select "Edit". You should see a bunch of inherited values that supposedly contain all the required directories similar to the ones you listed above. Uncheck the "Inherit from parent or project defaults" option. Recheck it and click "Ok".
- Repeat this for the includes, library directories, etc. -Click on "Apply" and "Ok" - Rebuild the project and check if this worked.

我发现以下技巧对我有用,也许它也适用于您的情况: - 打开 VS2010 的新实例 - 使用 def 设置创建新的控制台应用程序。- 尝试编译:应该有一些错误 - 打开“属性管理器” - 调出项目的 Microsoft.Cpp.Win32.user 属性表 - 单击 VC++ 目录 - 单击“可执行目录”字段。那应该显示一个下拉列表,单击下拉列表并选择“编辑”。您应该会看到一堆继承的值,这些值应该包含与上面列出的目录类似的所有必需目录。取消选中“从父级或项目默认值继承”选项。重新检查并单击“确定”。
- 对包含、库目录等重复此操作。 - 单击“应用”和“确定”

I only needed to do this once. After closing VS and creating a new project, I could just compile. Before I discovered this, I manually removed all inherited values and added absolute paths to all the VS and SDK directories. That also worked, but was a lot more work.

我只需要这样做一次。关闭VS并创建一个新项目后,我就可以编译了。在我发现这一点之前,我手动删除了所有继承的值,并为所有 VS 和 SDK 目录添加了绝对路径。这也有效,但需要做更多的工作。

回答by Leniel Maccaferri

The system could not find the Visual C++ compiler (CL.exe)...

系统找不到 Visual C++ 编译器 (CL.exe)...

Things you should try:

你应该尝试的事情:

  • Rerun the Visual Studio 2010 installer and make sure you selected to install Visual C++ tools for your platform (either x86 or amd64).

  • Run the installer in repair mode.

  • 重新运行 Visual Studio 2010 安装程序并确保您选择为您的平台(x86 或 amd64)安装 Visual C++ 工具。

  • 以修复模式运行安装程序。

If this does not solve your problem:

如果这不能解决您的问题:

回答by ken

I had the same problem and found this page via a search, but I didn't quite grasp Ralf's answer about the user property sheet, and had no luck with re-installing. I think Ralf's answer would have worked for me, but I was looking at the "Property Pages" dialog that comes up when you right-click on a project in the Solution Explorer and choose "Properties". I didn't realize that it was different from the "Property Manager".

我遇到了同样的问题,通过搜索找到了这个页面,但我不太明白拉尔夫关于用户属性表的回答,并且没有重新安装。我认为 Ralf 的回答对我有用,但我正在查看当您右键单击解决方案资源管理器中的项目并选择“属性”时出现的“属性页面”对话框。没想到和“物业经理”不一样。

So, I asked on the msdn forum and got an answerand a nice explanation of property sheets. The solution that worked for me was to edit the user property sheet in a text editor and delete all the paths, leaving it empty like this:

所以,我在 msdn 论坛上提问并得到了答案对属性表的很好的解释。对我有用的解决方案是在文本编辑器中编辑用户属性表并删除所有路径,将其留空,如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

</Project>

The user property sheet is Microsoft.Cpp.Win32.user.propsunder <localappdata>\microsoft\msbuild\v4.0where <localappdata>is c:\users\<username>\appdata\localunder Win7.

用户属性表是Microsoft.Cpp.Win32.user.props根据 <localappdata>\microsoft\msbuild\v4.0其中<localappdata>c:\users\<username>\appdata\localWin7的下方。

回答by JHowIX

I have no idea why this worked but I was getting this error and installing Visual Studio Power Commandssolved this for me. This extension adds the Configuration Properties -> VC++ Directories that allows you to directly modify the ExecutableDirectories macro, it might have something to do with that.

我不知道为什么会这样,但我收到了这个错误,安装Visual Studio Power Commands为我解决了这个问题。此扩展添加了配置属性 -> VC++ 目录,允许您直接修改 ExecutableDirectories 宏,它可能与此有关。