I think you need letters that should be 27 characters, not 26, but instead of letters += temp (which increments the line each time), use letters[26] = temp[0] .
... at this point you can completely stop temp :
string letters = "abcdefghijklmnopqrstuvwxyz."; while (true) { letters[26] = letters[0]; for (int i = 0; i < 26; i++) { letters[i] = letters[i + 1]; cout << letters[i]; } cin.get(); }
[edit]
Although a more natural way to deal with this is to use arithmetic for the characters themselves. The expression 'a' + ((c - 'a' + n) % 26) will shift a char c by n , placing Caesar's style.
source share