#include <iomanip>
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
class STLstring
{
private:
string word;
public:
STLstring()
{
word = "";
}
void setWord(string w);
string getWord();
};
class EncryptString:public STLstring
{
private:
void encrypt();
void decrypt();
};
/*****************IMPLEMENTATION*******************/
void STLstring::setWord(string w)
{
void encrypt();
word = w;
cout << word;
}
string STLstring::getWord()
{
void decrypt();
return word;
}
void EncryptString::encrypt()
{
string temp = getWord();
temp = (temp - 5) %26;
setWord(temp);
}
void EncryptString::decrypt()
{
string temp = getWord();
setWord(temp);
}
int main()
{
string word = "";
EncryptString EncrptStr;
cout << "Enter a word and I will encrypt it so that you cannot read it any longer." << endl;
getline(cin, word);
cout << "\nHere is the encrypted word..." << endl;
EncrptStr.setWord(word);
cout << "\nHere is the decrypted word..." << endl;
cout << EncrptStr.getWord() << endl;
}
temp = (temp - 5) %26;
错误错误说:在没有比赛的“操作符 - '温度 - 5' 我我试图做的是一个ceasar密码,我知道我还没有完成密码,但我认为即使完成它,错误仍然会出现,我应该在课堂上做一个重载操作符?如果是这样如何?我认为重载只在两个类之间。
不要为字符串实现'operator-'。 –
@LightnessRacesinOrbit:我澄清了我的答案的一部分。谨慎解释你的评论? – wallyk
这样的操作符会令人惊讶,它的语义不清。避免创造一个诱惑;这将是一个运营商滥用的完美例子。看到urzeit的答案。 –