Bob*_*bby -2 c++ string boolean function
我正在做一个要求我使用函数检查两个字符串是否相等的赋值.我一直在第20行得到一个解析错误,这里调用了函数,我不知道出了什么问题.如果您发现可能导致问题的原因,请查看并告诉我.谢谢!
#include <iostream>
#include <string>
using namespace std;
bool checker(string firstWordParameter, string secondWordParameter);
int main()
{
string firstWord, secondWord;
bool match;
cout << "Hello user.\n"
<< "This program will determine whether two words are the same.\n"
<< "Please enter your first word you would like to check: ";
getline(cin, firstWord);
cout << "Great, now enter the second word: ";
getline(cin, secondWord);
match = bool checker(firstWord, secondWord);
if(match == true){
cout << "Match.";
}else{
cout << "Totally not a match.";
}
return 0;
}
bool checker(string firstWordParameter, string secondWordParameter)
{
if(firstWordParameter == secondWordParameter){
return true;
}else{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
尝试改变
match = bool checker(firstWord, secondWord);
Run Code Online (Sandbox Code Playgroud)
成
match = checker(firstWord, secondWord);
Run Code Online (Sandbox Code Playgroud)
20号线是
match = bool checker(firstWord, secondWord);
Run Code Online (Sandbox Code Playgroud)
将其更改为
match = checker(firstWord, secondWord);
Run Code Online (Sandbox Code Playgroud)
此外,当您在编译器中看到错误时,双击它然后它将显示带有错误的行.