我正在使用特定的密鑰解密文本的程序。我試圖使用replace()
,但它似乎沒有工作。例如,qwert
應解密爲hello
,但輸出爲hlllo
;在這種情況下中的w
被解密爲e
,但隨後被重新解密爲l
。替換行中的特定字符,C++
輸入:
xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj
should come out as:
the quick brown fox jumps over the lazy dog
I'm getting:
oga yaacd brozn aox gamav ovar oga lazy dog
我該如何解決這個問題?
int main()
{
// ...
myFile.open("decrypt.txt");
while (myFile.good())
{
getline(myFile, line2);
// now line2 is, e.g., "xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj"
// help here
for (int i = 0; i < 26; i++)
{
replace(line2.begin(), line2.end(), key[i], fox[i]);
}
v.push_back(line2);
}
myFile.close();
for (int i = 0; i < numline; i++)
{
cout << "line " << i <<" = " << v[i] << endl;
}
return 0;
}
好吧,我刪除了所有不必要的代碼,並解釋了一點點。 – acrogenesis 2012-01-30 23:21:19