Mikael said:
I there a function in the string class to replace an 'a' with an 'm', or
something similar?
Will I have to write a function iterating over every character in the
string to rot-13 encoding a string?
Here is an example code that creates new data type 'rot_string' which
upon instantiation
rot13'es a string.
#include <string>
#include <cctype>
#include <iostream>
struct rot_char_traits : public std::char_traits<char>
{
static char *copy(char *s1, const char *s2, size_t n) {
while (n--) *s1++ = isalpha(*s2 + 13) ? *s2++ + 13 : *s2++ -
13;
return s1 - n;
}
};
typedef std::basic_string<char, rot_char_traits> rot_string;
int
main()
{
rot_string nun = "aha"; // "aha" rot13'ed is "nun"
rot_string sync = "flap"; // "flap" rot13'ed is "sync"
std::cout << nun.c_str() << "\n";
std::cout << sync.c_str() << "\n";
return 0;
}
P.Krumins