我遇到了启动加密程序的问题。对于单个单词字符串,它的效果很好(例如,abcd),但是当我键入两个或三个或更多的单词(例如,abcd ab ac的一个句子)时,它不会要求输入密钥,而是会重写我输入的句子。我究竟做错了什么?提前致谢。代码:凯撒密码 - 怎么了?
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <conio.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
int main()
{
int key, l;
char choose;
string message;
cout<<"Type the message"<<endl;
cin>>message;
cout<<"Give me a key from 0 to 26"<<endl;
cin>>key;
for (int i=0,l=message.size(); i<=l; i++)
{
if (isalpha(message[i]))
{
if (isupper(message[i]))
{
cout<<(char)('A'+(message[i]-'A'+key)%26);
}
if (islower(message[i]))
{
cout<<(char)('a'+(message[i]-'a'+key)%26);
}
}
else
{
cout<<message[i];
}
}
return 0;
}
如果我们能看到你写的代码,这将更容易回答。否则,这是谁可以猜测和/或读你的思想的比赛。 – CoryKramer 2014-11-21 13:55:47
对不起,我对此有所作为。我编辑它。 – DominikM 2014-11-21 14:01:29
如果我运行它并输入几个单词,它不会重复我输入的句子;它要求一个键,然后打印我输入的第一个单词。你确定你正在运行这个程序吗? – molbdnilo 2014-11-21 14:08:29