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.
asked Nov 21, 2013 at 5:35
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"
.
answered Nov 21, 2013 at 5:47
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
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.
answered Apr 22, 2014 at 2:26
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.
asked Nov 21, 2013 at 5:35
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"
.
answered Nov 21, 2013 at 5:47
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
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.
answered Apr 22, 2014 at 2:26
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:
-
In the Solution Explorer window, right-click the project name, and then choose Properties to open the project Property Pages dialog.
-
In the Configuration drop-down, select All Configurations.
-
Select 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.
-
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.
-
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)
- 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
-
Proposed as answer by
-
Where is
‘Configuration Properties’?
Thanks
-
Proposed as answer by
Prizzy29
Monday, October 26, 2009 7:27 AM
-
Proposed as answer by
-
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
-
Proposed as answer by
-
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 headerUntick Precompiled Header
then Finished It
-
Edited by
SANJAY KHACHANE
Wednesday, June 6, 2012 11:08 AM
-
Edited by
-
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
-
Edited by
-
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
0 |
3434 / 2813 / 1249 Регистрация: 29.01.2016 Сообщений: 9,426 |
|
05.03.2018, 16:46 |
2 |
Добавлял данную библиотеку-не помогло. Куда добавлял? Как добавлял? В коде ничего такого не наблюдаю. И это не библиотека.
0 |
1 / 0 / 1 Регистрация: 26.12.2017 Сообщений: 35 |
|
05.03.2018, 16:50 [ТС] |
3 |
Не библиотеку, извиняюсь, а вот такой строчкой
0 |
3434 / 2813 / 1249 Регистрация: 29.01.2016 Сообщений: 9,426 |
|
05.03.2018, 16:52 |
4 |
а вот такой строчкой Код со строчкой покажи.
0 |
HerMak 1 / 0 / 1 Регистрация: 26.12.2017 Сообщений: 35 |
||||
05.03.2018, 16:52 [ТС] |
5 |
|||
0 |
nd2 3434 / 2813 / 1249 Регистрация: 29.01.2016 Сообщений: 9,426 |
||||
05.03.2018, 16:55 |
6 |
|||
Сообщение было отмечено HerMak как решение Решение
Это выше всех инклудов должно быть.
1 |