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

时间:2011-01-04 13:46:51

标签: c++ visual-studio-2010 compilation windows-xp-sp3

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

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

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

错误 -

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 :我对使用VS2010完全不熟悉,但有VS 2005的经验。

以下是我在“用户属性表”

下从VS2005添加到VS2010的目录列表

可执行文件 -

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

包含 -

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

图书馆 -

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

来源 -

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

4 个答案:

答案 0 :(得分:19)

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

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

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

答案 1 :(得分:6)

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

你应该尝试的事情:

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

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

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

答案 2 :(得分:5)

我遇到了同样的问题并通过搜索找到了此页面,但我并没有完全掌握Ralf关于用户属性表的答案,并且没有重新安装的运气。我认为Ralf的答案对我有用,但是当我在解决方案资源管理器中右键单击项目并选择“属性”时,我正在查看“属性页”对话框。我没有意识到它与“物业经理”不同。

所以,我在msdn论坛上询问了an answera nice explanation of property sheets。对我有用的解决方案是在文本编辑器中编辑用户属性表并删除所有路径,将其留空如下:

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

</Project>

用户属性表在Microsoft.Cpp.Win32.user.props<localappdata>\microsoft\msbuild\v4.0所在的<localappdata> Win7下的c:\users\<username>\appdata\local

答案 3 :(得分:0)

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