我正试图创建一个程序,对文件中的所有整数进行计数,并检查它们是否为偶数。我不断地把这个错误和"检查它们是否均匀"部分联系起来。这是我的代码:
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include <string>
using namespace std;
bool isNotEven(int&);
int main()
{
ifstream myfile("input.txt");
int numberTot = 0;
int numberOdd = 0;
int check = 1;
string line;
while(check != -1)
{
getline(myfile,line);
check = stoi(line);
if (check != -1)
numberTot++;
if (isNotEven(check) == true)
numberOdd++;
}
cout << "There are " << numberTot << " numbers in this file." << endl;
cout << "There are " << numberOdd << " odd numbers in this file." << endl;
char x;
cin >> x;
}
bool isNoteEven(int& x)
{
if (x%2 == 0)
return false;
else
return true;
}
我一直收到这个错误,我很困惑为什么它会出现
1> Lab4.cpp
1>Lab4.obj : error LNK2019: unresolved external symbol "bool __cdecl isNotEven(int &)" (?isNotEven@@YA_NAAH@Z) referenced in function _main
1>C:UsersNickDesktopCS1Lab4DebugLab4.exe : fatal error LNK1120: 1 unresolved externals
您拼写错误的函数名称是isNoteEven而不是isNotEven。