c++ - Visual Studio 2017 错误 - 找不到特定文件
问题描述
每次尝试运行代码时,我都会遇到同样的问题。“无法启动程序----系统找不到特定文件。我为以前版本的Visual Studio寻找了不同的解决方案,但它似乎不起作用。
这是出现的问题:
解决方案
问题是您的项目丢失了stdafx.h
。此文件由 MSVS 自动生成。
最简单的解决方法——至少如果你对 MSVS 比较陌生——就是简单地创建一个新项目,然后从原始的“损坏”项目中复制/粘贴你的源代码。
另一种解决方案是禁用“预编译头”:
https://msdn.microsoft.com/en-us/library/d7fz9ckx.aspx
如果在项目中不使用预编译头文件,请将源文件的 Create/Use Precompiled Header 属性设置为 Not Using Precompiled Headers。要设置此编译器选项,请执行以下步骤:
在项目的“解决方案资源管理器”窗格中,右键单击项目名称,然后单击“属性”。
在左窗格中,单击 C/C++ 文件夹。
单击预编译头节点。
在右窗格中,单击“创建/使用预编译头”,然后单击“不使用预编译头”。
注意:如果您选择禁用预编译头文件,请务必
#include "stdafx.h"
从所有源文件中删除。有关更多信息,请查看此处:
附录:
在 Visual Studio 中创建一个新的 C++ 项目应该创建一个新的 stdafx.h。
或者,“设置项目 > 属性 > 预编译头文件 > 不使用预编译头文件”,然后
#include stdafx.h
从 .cpp 文件中删除应该可以修复启动错误。
...但是还有第三种方法...
您可以手动创建自己的 stdafx.* 文件并将它们添加到项目中。
例子:
stdafx.h:
// stdafx.h : include file for standard system include files, or project
// specific include files that are used frequently, but are changed infrequently
#pragma once
// TODO: reference additional headers your program requires here
stdafx.cpp:
// stdafx.cpp : source file that includes just the standard includes
// hello_cpp.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H // and not in this file
targetver.h:
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>
推荐阅读
- azure - 订阅中的活动消息时更新订阅
- c# - 如何防止 ScintillaNET 控件自动滚动?
- python - 列表数据存储和更新列表
- python - 需要有关此错误的帮助:只能将列表(而不是“str”)连接到列表
- kotlin-flow - kotlin flow 没有从不同的函数发出值
- tensorflow - 限制CNN中不相关图像的概率百分比
- blazor - 如何在 Blazor 中编写自定义值更改事件处理程序?
- python - 如何正确地从文本中获取不会引发 InvalidSchema("No connection adapters were found for {!r}".format(url)) 错误的 URL?
- php - 如何在 Laravel 5.4 中验证多维数组并使用请求值作为参数?
- python - 将二叉树转换为路径