无效操作数的类型字符和常量字符[2]二元运算符

问题描述:

即时通讯我真的很困惑,为什么我不断收到此错误。我试图根据它们的ASCII值减去两个字符,例如“c” - “a”= 2,但是无论我做什么(我一直尝试不同的事情超过一个小时),我总是会打错误。请帮助我或澄清即将做的事情是不正确的。无效操作数的类型字符和常量字符[2]二元运算符

char vigenere_letter (char plain_text, char key_letter) { 
    int rotation; 
    string new_alphabet; 
    rotation = plain_text - "a"; 
    new_alphabet = rotate_left(rotation, alphabet); 
} 
+0

' “一”'是字符串,不是字符。你想''a'' – Steve

+0

你的意思是写'rotation = plain_text - 'a';'而不是? – user0042

+0

谢谢吨家伙!相当尴尬关于这一个! –

你的意思是写rotation = plain_text - 'a';

"a"char*(一 “串”,多个字符),而'a'是单个字符(char

+0

如错误消息所示,''a“'是一个”const char [2]“,而不是”char *“。 – melpomene

+0

欢迎您,因为您是新来宾,您可能需要阅读以下内容:https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – jpo38