我正在使用特定的密钥解密文本的程序。我试图使用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