C++ 致命错误 C1010 - Visual Studio 中的“stdafx.h” 如何纠正?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20113280/
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
fatal error C1010 - "stdafx.h" in Visual Studio how can this be corrected?
提问by user1800967
I compile the following code but I get a compile error in Visual Studio that I cannot understand.
我编译了以下代码,但在 Visual Studio 中出现了一个我无法理解的编译错误。
#include <iostream>
using namespace std;
int main()
{
int matchCount, findResult;
long childPID;
string userInput = "blank";
// string to be searched through
string longString = "The PPSh-41 is a Soviet submachine gun designed by Georgi Shpagin as an inexpensive, simplified alternative to the PPD-40.";
while (userInput.compare("!wq"));
{
// reset variables for reuse
matchCount = 0;
findResult = -1;
cout << "Please enter a word/s to search for (!wq to exit): "; // prompts user for string to search for
cin >> userInput; // takes user input
if (userInput.compare("!wq")) // checks user input to see if they still wish to search for a string
{
childPID = fork();
if (childPID == 0)
{
while (findResult < longString.length)
{
findResult = longString.find(userInput, findResult + 1, userInput.length);
if (findResult < longString.length)
matchCount++;
}
cout << "There are " << matchCount << " instances of " << userInput << " in longString." << endl;
}
else
cout << "childPID != 0" << endl;
}
else
cout << "User has chosen to exit. Exiting." << endl;
}
return 0;
}
The error reads:
错误如下:
"wordcount.cpp(57) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?"
“wordcount.cpp(57):致命错误 C1010:在查找预编译头文件时意外结束文件。您是否忘记将 '#include “stdafx.h”' 添加到您的源代码中?”
I don't believe I need a header file to run this code. Thank you for all your help in advance.
我不相信我需要一个头文件来运行这段代码。提前感谢您的所有帮助。
回答by Glenn Teitelbaum
Look at https://stackoverflow.com/a/4726838/2963099
看https://stackoverflow.com/a/4726838/2963099
Turn off pre compiled headers:
关闭预编译的头文件:
Project Properties -> C++ -> Precompiled Headers
set Precompiled Header
to "Not Using Precompiled Header"
.
设置Precompiled Header
为"Not Using Precompiled Header"
。
回答by asif
回答by Zahid Rouf
Create a new "Empty Project" , Add your Cpp file to the new project, delete the line that includes stdafx.
创建一个新的“空项目”,将您的 Cpp 文件添加到新项目中,删除包含 stdafx 的行。
Done.
完毕。
The project no longer needs the stdafx. It is added automatically when you create projects with installed templates.
该项目不再需要 stdafx。当您使用已安装的模板创建项目时,它会自动添加。