我編譯下面的代碼,但我在Visual Studio中遇到了編譯錯誤,我無法理解。致命錯誤C1010 - VisualStudio中的「stdafx.h」如何糾正?
#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:在查找預編譯頭文件的意外結束你忘了加上「#包括‘stdafx.h中’ '來源?'
我不相信我需要一個頭文件來運行此代碼。感謝您提前給予您所有的幫助。
如果錯誤消息提示有變化,爲什麼不試試看看會發生什麼? – abiessu
我做到了。只有更多的錯誤出現。不止一個錯誤。 – user1800967
哪個編譯器?什麼OS?什麼是出現的新錯誤的一些例子?什麼是你的編譯設置和/或什麼是你的編譯命令? – abiessu