Ошибка с1010 visual studio

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.

Glenn Teitelbaum's user avatar

asked Nov 21, 2013 at 5:35

user1800967's user avatar

5

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".

Community's user avatar

answered Nov 21, 2013 at 5:47

Glenn Teitelbaum's user avatar

Glenn TeitelbaumGlenn Teitelbaum

10.1k3 gold badges36 silver badges80 bronze badges

3

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

#include <stdafx.h>

Visit here to understand Precompiled Headers

answered Nov 21, 2013 at 5:48

asif's user avatar

asifasif

9758 silver badges16 bronze badges

4

Create a new «Empty Project» , Add your Cpp file to the new project, delete the line that includes stdafx.

Done.

The project no longer needs the stdafx. It is added automatically when you create projects with installed templates.
enter image description here

answered Apr 22, 2014 at 2:26

Zahid Rouf's user avatar

Zahid RoufZahid Rouf

1,5912 gold badges11 silver badges10 bronze badges

1

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.

Glenn Teitelbaum's user avatar

asked Nov 21, 2013 at 5:35

user1800967's user avatar

5

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".

Community's user avatar

answered Nov 21, 2013 at 5:47

Glenn Teitelbaum's user avatar

Glenn TeitelbaumGlenn Teitelbaum

10.1k3 gold badges36 silver badges80 bronze badges

3

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

#include <stdafx.h>

Visit here to understand Precompiled Headers

answered Nov 21, 2013 at 5:48

asif's user avatar

asifasif

9758 silver badges16 bronze badges

4

Create a new «Empty Project» , Add your Cpp file to the new project, delete the line that includes stdafx.

Done.

The project no longer needs the stdafx. It is added automatically when you create projects with installed templates.
enter image description here

answered Apr 22, 2014 at 2:26

Zahid Rouf's user avatar

Zahid RoufZahid Rouf

1,5912 gold badges11 silver badges10 bronze badges

1

description title ms.date f1_keywords helpviewer_keywords ms.assetid

Learn more about: Fatal Error C1010

Fatal Error C1010

09/03/2019

C1010

C1010

dfd035f1-a7a2-40bc-bc92-dc4d7f456767

Fatal Error C1010

unexpected end of file while looking for precompiled header. Did you forget to add ‘#include name‘ to your source?

Remarks

An include file specified by /Yu isn’t listed in the source file. This option is enabled by default in many Visual Studio C++ project types. The default include file specified by this option is pch.h, or stdafx.h in Visual Studio 2017 and earlier.

In the Visual Studio environment, use one of the following methods to resolve this error:

  • Make sure you haven’t inadvertently deleted, renamed, or removed the pch.h header file or pch.cpp source file from the current project. (In older projects, these files may be named stdafx.h and stdafx.cpp.)

  • Make sure the pch.h or stdafx.h header file is included before any other code or preprocessor directives in your source files. (In Visual Studio, this header file is specified by the Precompiled Header File project property.)

  • You can turn off precompiled header use. If you turn off precompiled headers, it may severely impact build performance.

To turn off precompiled headers

To turn off precompiled header use in a project, follow these steps:

  1. In the Solution Explorer window, right-click the project name, and then choose Properties to open the project Property Pages dialog.

  2. In the Configuration drop-down, select All Configurations.

  3. Select the Configuration properties > C/C++ > Precompiled Headers property page.

  4. 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.

  5. In the Solution Explorer window, right-click the pch.cpp source file in your project. (In older projects, the file may be named stdafx.cpp.) Choose Exclude from Project to remove it from the build.

  6. Use the Build > Clean solution menu command for each configuration you build, to delete any project_name.pch files in your intermediate build directories.

See also

Precompiled header files
/Yc (Create precompiled header file)
/Yu (Use precompiled header file)

RRS feed

  • Remove From My Forums
  • Question

  • fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add ‘#include «stdafx.h»‘ to your source?

    I am using Visual Studio 2005 Academic Edition.

    I clicked «Tool»=>Options=>Debugging=>Edit and Continue.

    Let «Allow precomping» unchecked then.

    Why does this error occury?

    Thanks! 

Answers

  • «Did you forget to add #include «stdafx.h» to your source»?

All replies

  • «Did you forget to add #include «stdafx.h» to your source»?

  • I have generated source code and was trying to compile in release mode (instead of debug).  I got this error.  Putting in the #include «stdafx.h» does not fix the problem.  Anyone know what is going on and why I am getting this error in Release mode and not in Debug mode?

  • I figured out what the problem was.  The entire project needed to be marked as ‘Not Using Precompiled Headers’ in the property pages.  This is under the ‘Configuration Properties’->C/C++->’Precompiled Headers’.  You could just single out the one file if you wanted to also.

    I then was getting some linker unresolved external errors after doing that.  Make sure you also check for any libraries that need to be linked against.  I had (NOINHERIT) in my Additional Dependencies field of the properties.  That field is under the ‘Configuration Properties’->Linker->Input.

    Just wanted to put on the board what I found in case anyone else has these easy setup issues.  These things are different from what I am used to or at least in different places.

    • Proposed as answer by

      Friday, October 7, 2011 7:40 PM

  • Where is

    ‘Configuration Properties’?

    Thanks

    • Proposed as answer by
      Prizzy29
      Monday, October 26, 2009 7:27 AM

  •  The Steve340 wrote:

    I have generated source code and was trying to compile in release mode (instead of debug).  I got this error.  Putting in the #include «stdafx.h» does not fix the problem.  Anyone know what is going on and why I am getting this error in Release mode and not in Debug mode?


  • Once the C++ is open in a project = Tools/options/”edit/countine” you click on the left side / and then close to the bottom is the option to add or remove ‘Precompiled Headers’

    I had an issue, where there ‘Precompiled Headers’ came out of no where, I didn’t even chose it but, I googled the issue and came up with the site. An I read the idea’s on here an searched for it in C++ search and it told me how to do. An I thought I would share the little info.

    • Proposed as answer by
      SANJAY KHACHANE
      Wednesday, June 6, 2012 10:58 AM
    • Unproposed as answer by
      SANJAY KHACHANE
      Wednesday, June 6, 2012 10:59 AM
    • Proposed as answer by
      SANJAY KHACHANE
      Wednesday, June 6, 2012 10:59 AM

  • Go To 

    I am using Visual Studio 2010.

    Clicked New Project —> Visual C++ —> Win32 Console Application —>

    Enter Name Of Application—> Click Ok

    Show «Win32 Application Wizard» — > Click Next —>

    In Scrine Show 

    Additional options: 

    Empty project 
    Export symbols 
    Precompiled header 

    Untick Precompiled Header

    then Finished It

    • Edited by
      SANJAY KHACHANE
      Wednesday, June 6, 2012 11:08 AM

  • Hi..ardmore,

    I was having same problem, but solved it by following manner..

    Open property of that particular page and  go to confi. Property -> c/c++ -> precompiled headers -> set this value to “Not using precompiled Headers”

    • Edited by
      Mayur.Dabhi
      Thursday, September 20, 2012 11:06 AM

  • Thank you soo much.. its works fine steve


HerMak

1 / 0 / 1

Регистрация: 26.12.2017

Сообщений: 35

1

05.03.2018, 16:45. Показов 9581. Ответов 5

Метки нет (Все метки)


Студворк — интернет-сервис помощи студентам

Решил попробовать сделать змейку на чистом с++, но тут какая то ошибка, игру разрабатываю в Visual studio 2017 код ошибки С1010
непредвиденный конец файла во время поиска предкомпилированного заголовка. Возможно, вы забыли добавить директиву «#include «stdafx.h»»
Добавлял данную библиотеку-не помогло.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std;
const int width = 20;
const int height = 20;
int x, y;
int fruitx, fruity, score;
bool GameOver;
enum eDirection { STOP = 0, LEFT, RIHGT, UP, DOWN };
eDirection dir;
 
void SetUp()
{
    GameOver = false;
    dir = STOP;
    x = width / 2;
    y = height / 2;
    fruitx = rand() % width;
    fruity = rand() % height;
    score = 0;
}
void Draw()
{
    system("cls");
    for (int i = 0; i<width; i++)cout << "#";
    cout << endl;
 
    for (int i = 0; i<height; i++)
    {
        for (int j = 0; j<width; i++)
        {
            if (j == 0 || j == width - 1)
                cout << "#";
            cout << " ";
        }
        cout << endl;
    }
 
    for (int i = 0; i<width ; i++) cout << "#";
    cout << endl;
}
void Input()
{
 
}
void Logic()
{
 
}
int main(int argc, char** argv) {
    SetUp();
    while (!GameOver)
    {
        Draw();
        Input();
        Logic();
    }
    return 0;
}



0



3434 / 2813 / 1249

Регистрация: 29.01.2016

Сообщений: 9,426

05.03.2018, 16:46

2

Цитата
Сообщение от HerMak
Посмотреть сообщение

Добавлял данную библиотеку-не помогло.

Куда добавлял? Как добавлял? В коде ничего такого не наблюдаю. И это не библиотека.



0



1 / 0 / 1

Регистрация: 26.12.2017

Сообщений: 35

05.03.2018, 16:50

 [ТС]

3

Не библиотеку, извиняюсь, а вот такой строчкой
#include «stdafx.h



0



3434 / 2813 / 1249

Регистрация: 29.01.2016

Сообщений: 9,426

05.03.2018, 16:52

4

Цитата
Сообщение от HerMak
Посмотреть сообщение

а вот такой строчкой
#include «stdafx.h

Код со строчкой покажи.



0



HerMak

1 / 0 / 1

Регистрация: 26.12.2017

Сообщений: 35

05.03.2018, 16:52

 [ТС]

5

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include "stdafx.h"
using namespace std;
const int width = 20;
const int height = 20;
int x, y;
int fruitx, fruity, score;
bool GameOver;
enum eDirection { STOP = 0, LEFT, RIHGT, UP, DOWN };
eDirection dir;
 
void SetUp()
{
    GameOver = false;
    dir = STOP;
    x = width / 2;
    y = height / 2;
    fruitx = rand() % width;
    fruity = rand() % height;
    score = 0;
}
void Draw()
{
    system("cls");
    for (int i = 0; i<width; i++)cout << "#";
    cout << endl;
 
    for (int i = 0; i<height; i++)
    {
        for (int j = 0; j<width; i++)
        {
            if (j == 0 || j == width - 1)
                cout << "#";
            cout << " ";
        }
        cout << endl;
    }
 
    for (int i = 0; i<width ; i++) cout << "#";
    cout << endl;
}
void Input()
{
 
}
void Logic()
{
 
}
int main(int argc, char** argv) {
    SetUp();
    while (!GameOver)
    {
        Draw();
        Input();
        Logic();
    }
    return 0;
}



0



nd2

3434 / 2813 / 1249

Регистрация: 29.01.2016

Сообщений: 9,426

05.03.2018, 16:55

6

Лучший ответ Сообщение было отмечено HerMak как решение

Решение

Цитата
Сообщение от HerMak
Посмотреть сообщение

C++
1
#include "stdafx.h"

Это выше всех инклудов должно быть.



1



  • Ошибка с0287 уаз патриот абс
  • Ошибка с100а митсубиси лансер 10
  • Ошибка с1004 фиат панда
  • Ошибка с1003 фиат панда
  • Ошибка с1000 митсубиси лансер 10