Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我在visual studio 2017中使用代码中的头stdafx.h时出错_C++ - Fatal编程技术网

C++ 我在visual studio 2017中使用代码中的头stdafx.h时出错

C++ 我在visual studio 2017中使用代码中的头stdafx.h时出错,c++,C++,这是代码。我得到以下错误,我做错了什么?我正在使用visual studio 2017 1> ---构建已启动:项目:Print1,配置:调试Win32--- 1> Print1.cpp 1> c:\users\kiwiblazer\source\repos\print1\print1\print1.cpp4:致命错误C1010:查找预编译头时出现意外的文件结尾。您是否忘记在源代码中添加“include pch.h”? 1> 已完成生成项目Print1.vcxproj-失败。 ======生成:

这是代码。我得到以下错误,我做错了什么?我正在使用visual studio 2017

1> ---构建已启动:项目:Print1,配置:调试Win32--- 1> Print1.cpp 1> c:\users\kiwiblazer\source\repos\print1\print1\print1.cpp4:致命错误C1010:查找预编译头时出现意外的文件结尾。您是否忘记在源代码中添加“include pch.h”? 1> 已完成生成项目Print1.vcxproj-失败。 ======生成:0成功,1失败,0最新,0跳过==========


你的代码不正确。请张贴完整的代码。例如,代码中缺少main的右括号,这可能是失败的原因

如果代码正确,请检查解决方案的配置属性->C/C++->预编译头属性,并相应更改预编译头文件。

错误日志显示您是否忘记添加“include pch.h”。这是因为他们将预编译头名称更改为pch.h。对于VS17

尝试将stdafx.h替换为pch.h。我认为这是最简单的解决办法

#include "pch.h"
#include <iostream>

using namespace std;

int main()
{
cout << "Never fear, C++ is here! ";
return 0;
}

下一次尝试在询问此问题之前搜索确切的错误:
#include "pch.h"
#include <iostream>

using namespace std;

int main()
{
cout << "Never fear, C++ is here! ";
return 0;
}