How do i increment letters in c++?

后端 未结 8 1326
渐次进展
渐次进展 2021-01-05 05:30

I\'m creating a Caesar Cipher in c++ and i can\'t figure out how to increment a letter.

I need to increment the letter by 1 each time and return the next letter in t

8条回答
  •  感动是毒
    2021-01-05 06:07

    Does letter++ work? All in all char is a numeric type, so it will increment the ascii code. But I believe it must be defined as char letter not an array. But beware of adding one to 'Z'. You will get '[' =P

    #include 
    
    int main () {
        char a = 'a';
        a++;
        std::cout << a;
    }
    

    This seems to work well ;)

提交回复
热议问题