簡體   English   中英

我該如何解決? (錯誤:'operator==' 不匹配(操作數類型是 'std::string' {aka 'std::__cxx11::basic_string'} 和 'int')

[英]How do I fix this? (error: no match for ‘operator==’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string’} and ‘int’)

所以我的基本程序(我剛剛開始)看起來像這樣:

#include <iostream>

using namespace std;

string PIN;

int main()
{
    cout << "witaj w naszym banku" << endl;
    cout << "podaj numer PIN: ";
    cin >> PIN;

    if (PIN == 0137) {
        cout << "Poprawny PIN";
    }

    else {
        cout << "Niepoprawny PIN";
    }
    return 0;
}

當我嘗試運行它時,我收到以下消息:


    main.cpp:21:20: error: no match for ‘operator==’ (operand types are ‘std::string’ {aka ‘std::__cxx11::basic_string’} and ‘int’)

對於這部分代碼:


    if (PIN==0137)

我不知道該怎么辦

像這樣寫

if (PIN == "0137"){
         ....
          }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM