【问题标题】:Verify if two strings are equal in C++ [closed]验证两个字符串在 C++ 中是否相等 [关闭]
【发布时间】:2014-02-26 06:08:36
【问题描述】:

我正在做一个作业,要求我使用一个函数来检查两个字符串是否相等。我在调用函数的第 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;
    }
}

【问题讨论】:

  • 如果您能告诉我们第 20 行在哪里就太好了...
  • 你为什么不看看第 20 行几分钟?或者至少只是发布周围的(+- 1 行)代码? :p

标签: c++ string function boolean


【解决方案1】:

第 20 行是

 match = bool checker(firstWord, secondWord);

改成

match = checker(firstWord, secondWord);

此外,当您在编译器中看到错误时,双击它,它会显示错误所在的行。

【讨论】:

  • 谢谢。是的,我知道这是第 20 行,我只是不明白为什么它不喜欢我的函数调用。感谢您的帮助,这个网站的用户可能很恶毒。
  • 谢谢,如果您接受我的回答将不胜感激(打勾)
【解决方案2】:

尝试改变

match = bool checker(firstWord, secondWord);

进入

match = checker(firstWord, secondWord);

【讨论】:

  • 非常感谢,这就是我所需要的。现在工作:)
猜你喜欢
  • 2021-02-13
  • 2020-01-02
  • 2011-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多