我收到以下錯誤:比較運算符==不工作,我如何使它工作? [CPP]
C:\Users\*******\Documents\CodeBlocksProjects\encryptText\main.cpp||In function 'int main()':|
C:\Users\*******\Documents\CodeBlocksProjects\encryptText\main.cpp|14|error: no match for 'operator==' in 'givenText == 1'|
C:\Users\*******\Documents\CodeBlocksProjects\encryptText\main.cpp|25|error: no match for 'operator==' in 'givenText == 2'|
||=== Build finished: 2 errors, 0 warnings ===|
使用下面的代碼:
#include <iostream>
#include <string>
#include "encrypt.h"
#include "decrypt.h"
using namespace std;
int main() {
startOver:
string givenText, pass;
cout << "Encrypt (1) or Decrypt (2)?" << endl << "Choice: ";
getline(cin, givenText);
if (givenText == 1) {
cout << endl << "Plain-Text: ";
getline(cin, givenText);
cout << endl << "Password: ";
getline(cin, pass);
cout << endl << encrypt(givenText, pass) << endl << "Restart? (Y/N)";
getline(cin, givenText);
if (givenText == "Y") {
cout << endl;
goto startOver;
}
} else if (givenText == 2) {
cout << endl << "Ciphered-Text: ";
getline(cin, givenText);
cout << endl << "Password: ";
getline(cin, pass);
cout << endl << decrypt(givenText, pass) << endl << "Restart? (Y/N)";
getline(cin, givenText);
if (givenText == "Y") {
cout << endl;
goto startOver;
}
} else {
cout << endl << "Please input 1 or 2 for choice." << endl;
goto startOver;
}
return 0;
}
我認爲這將是簡單的,如果(X == Y)之類的事情,但我想不是。我想要做什麼來解決這個問題?提前致謝!