简体   繁体   English

visual studio 2019 - C++ 无法打开源文件

[英]visual studio 2019 - C++ cannot open source file

I am using Microsoft Visual Studio Community 2019 Version 16.8.4 on a Windows 10 machine.我在 Windows 10 机器上使用 Microsoft Visual Studio Community 2019 版本 16.8.4。

I have established that my include files live in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include" because I can actually see them listed there.我已经确定我的包含文件位于“C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include”中,因为我实际上可以看到它们列在那里。 However, I get an error with the line #include <cstdio> .但是, #include <cstdio>行出现错误。

I have tried right click on project name to bring up a context from which I chose 'Properties'.我尝试右键单击项目名称以调出我选择“属性”的上下文。 From the "Solution Project1 Property Pages", I selected "Debug Source Files" and then entered the full directory path to the include files.在“Solution Project1 Property Pages”中,我选择了“Debug Source Files”,然后输入包含文件的完整目录路径。

I still get the error我仍然收到错误

You need to add the directory where the headers are found to the project properties under either C/C++ -> Additional include directories or VC++ -> Include directories.您需要将找到标头的目录添加到 C/C++ -> Additional include 目录或 VC++ -> Include 目录下的项目属性中。

And note that you need to make sure that the directory is added for all project configurations/platforms you wish to be able to build.请注意,您需要确保为您希望能够构建的所有项目配置/平台添加了该目录。 The Debug source files item is only so that files can be found when running the debugger and have nothing to do with the project build stage. Debug source files 项只是为了在运行调试器时可以找到文件,与项目构建阶段无关。

I ran Visual Studio Installer and noted that one of the workloads, 'Desktop development with C++' had not been activated.我运行 Visual Studio Installer 并注意到其中一项工作负载“使用 C++ 进行桌面开发”尚未激活。 After activating it and downloading the required or missing binaries, I am now able to create an empty project using an example of the quintessential 'Hello World' program such as #include int main(){printf("Hello, world");return 0;}激活它并下载所需或缺少的二进制文件后,我现在可以使用典型的“Hello World”程序示例创建一个空项目,例如#include int main(){printf("Hello, world");return 0;}

#include <cstdio> is part of the C++ Standard Library headers, if you are getting the error E1696: 'cannot open source file , you might have to retarget the solution/project. #include <cstdio>是 C++ 标准库标头的一部分,如果您收到错误E1696: 'cannot open source file ”,您可能必须重新定位解决方案/项目。 Do the following:请执行下列操作:

  1. Right-click the Solution in the Solution Explorer pane;右键单击解决方案资源管理器窗格中的解决方案;
  2. Retarget solution;重定向解决方案;
  3. Follow the steps/press OK.按照步骤/按确定。

It worked for me when I couldn't find Standard Library headers, hopefully, it works for you as well.当我找不到标准库标题时,它对我有用,希望它也对你有用。

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

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