今天,我開始學習C++了一下,我開始用簡單的代碼來理解,但這個牌子讓我困惑C++ - 布爾返回值,那麼驗證它
#include <iostream>
using namespace std;
class MyVar
{
public:
MyVar(){
cout << "this is constructor" << endl;
}
void accesscheckpass(string x){
checkpass(x);
}
private:
bool checkpass(string x){
if(x == "password"){
return true;
}
}
};
int main()
{
int inputpass;
cout << "please enter your password\n" << endl;
cin >> inputpass;
MyVar MyAccess;
if(MyAccess.accesscheckpass(inputpass) == true){
cout << "welcome user 1" << endl;
}else{
cout << "get lost !" << endl;
}
}
我想驗證用戶時,他/她輸入密碼,然後當我要編譯它時,編譯器返回狀態「無效轉換從'int'到'const char *'[-fpermissive] |」,請有人修復我的代碼並解釋什麼我錯了 ?
檢查編譯器會報錯哪一行,然後看看你在那裏調用哪個函數,然後比較函數期望的類型和傳遞它的類型。 – PlasmaHH