I'm having some issues with a part of a C++ program I'm writing to encode and decode a Playfair cipher. The part of the program I'm having issues with is the first step (unfortunate, I know), which involves removing all whitespace, punctuation, and non-alphabet characters. This is what I have:
std::string step1(std::string plaintext)
{
plaintext.erase(remove_if(plaintext.begin(), plaintext.end(),
std::not1(std::ptr_fun(std::isalpha))));
plaintext.erase(remove_if(plaintext.begin(), plaintext.end(),
std::ptr_fun(std::ispunct)));
return plaintext;
}
The output is good, except it adds characters at the end of the string once cleaned. Usually, the extra characters are copies of characters found at the end of the cleaned input. I can't, for the life of me, figure out why this is happening. Any ideas?
Aucun commentaire:
Enregistrer un commentaire