致命错误C1010 - Visual Studio中的“stdafx.h”如何纠正?

时间:2013-11-21 05:35:28

标签: c++ visual-studio compiler-construction header

我编译以下代码但是我在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;
}

错误如下:

“wordcount.cpp(57):致命错误C1010:查找预编译标题时意外结束文件。您是否忘记将”#include“stdafx.h”'添加到源代码中?“

我认为我不需要头文件来运行此代码。提前感谢您的帮助。

3 个答案:

答案 0 :(得分:98)

查看https://stackoverflow.com/a/4726838/2963099

关闭预编译的标题:

Project Properties -> C++ -> Precompiled Headers

Precompiled Header设为"Not Using Precompiled Header"

答案 1 :(得分:19)

项目的每个源文件的第一行必须如下:

#include <stdafx.h>

访问here以了解预编译标题

答案 2 :(得分:5)

创建一个新的&#34; 空项目&#34; ,将您的Cpp文件添加到新项目,删除包含stdafx的行。

完成。

该项目不再需要stdafx。使用已安装的模板创建项目时会自动添加它。 enter image description here