我正在學習使用C++,並決定創建一個密碼程序,用戶被要求輸入密碼並將用戶輸入與密碼進行比較,並返回錯誤或權限。出於某種原因,這個程序總是返回一個錯誤,我不知道爲什麼。它必須與比較字符串有關,但我不確定。簡單的C++密碼程序
#include <iostream>
#include <string>
using namespace std;
int main(){
string pass = "password";
string input;
cout << "What is your password: ";
cin >> input;
if (input==pass){
cout << "Correct" << endl;
}else{
cout << "Wrong" << endl;
}
return 0;
}
我很想從程序員誰以任何方式使用C更深諳++作爲我剛剛從Python和過渡有點岩石轉移到C++一些幫助。
[Works fine](http://coliru.stacked-crooked.com/a/9d443e4db3d55cd3) – chris
實際代碼中的密碼字符串是否包含空格字符? – timrau
這是實際的測試代碼,我在這裏發佈沒做任何更改。並將'string pass ='password''更改爲'string pass =「password \ r」'不起作用。 – LoreleiRS