use*_*967 46 c++ compiler-construction header visual-studio
我编译以下代码,但我在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;
}
Run Code Online (Sandbox Code Playgroud)
错误如下:
"wordcount.cpp(57):致命错误C1010:在查找预编译头文件时意外结束文件.您是否忘记在源代码中添加"#include"stdafx.h"'?"
我不相信我需要一个头文件来运行此代码.提前感谢您的帮助.
Gle*_*aum 103
关闭预编译的标题:
Project Properties -> C++ -> Precompiled Headers
Run Code Online (Sandbox Code Playgroud)
设置Precompiled Header为"Not Using Precompiled Header".
asi*_*sif 21
项目的每个源文件的第一行必须如下:
#include <stdafx.h>
Run Code Online (Sandbox Code Playgroud)
访问此处以了解预编译标题
| 归档时间: |
|
| 查看次数: |
106496 次 |
| 最近记录: |