Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fatal error C1010 - "stdafx.h" in Visual Studio how can this be corrected?

I compile the following code but I get a compile error in Visual Studio that I cannot understand.

#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?"

I don't believe I need a header file to run this code. Thank you for all your help in advance.

like image 202
user1800967 Avatar asked Nov 21 '13 05:11

user1800967


People also ask

What is Stdafx h in Visual Studio?

Defination: "Stdafx. h" is a precompiled header. Precompiled means once compiled no need to compile again. stdafx. h is basically used in Microsoft Visual Studio to let the compiler know that the files are once compiled and no need to compile it from scratch.

How do I get rid of pch h in Visual Studio?

To turn off precompiled headersSelect the Configuration properties > C/C++ > Precompiled Headers property page. In the property list, select the drop-down for the Precompiled Header property, and then choose Not Using Precompiled Headers. Choose OK to save your changes.

Can not open include Stdafx H?

To turn it off, open the Visual C++ Component Properties dialog and in the tab "Includes" delete the text in the "Initial Source Includes". Another possibility is to create an empty "stdafx. h" file. For more information about precompiled header files, refer to the Microsoft knowledge base.

What is pch H in C++?

pch stands for precompiled header. In computer programming, a precompiled header is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler.


2 Answers

Look at https://stackoverflow.com/a/4726838/2963099

Turn off pre compiled headers:

Project Properties -> C++ -> Precompiled Headers

set Precompiled Header to "Not Using Precompiled Header".

like image 154
Glenn Teitelbaum Avatar answered Oct 17 '22 05:10

Glenn Teitelbaum


The first line of every source file of your project must be the following:

#include <stdafx.h>

Visit here to understand Precompiled Headers

like image 28
asif Avatar answered Oct 17 '22 06:10

asif