验证C 中的两个字符串是否相等

Verify if two strings are equal in C++

本文关键字:字符串 两个 是否 验证      更新时间:2023-10-16

我正在做一个分配,要求我使用功能检查两个字符串是否相等。我在第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;
    }
}

尝试更改

match = bool checker(firstWord, secondWord);

进入

match = checker(firstWord, secondWord);

第20行是

 match = bool checker(firstWord, secondWord);

将其更改为

match = checker(firstWord, secondWord);

同样,当您看到编译器中的错误时,请双击它,然后向您显示错误。