凯撒密码 - 怎么了?
Caesar cipher - What's wrong?
我在启动加密程序时遇到问题。对于单个单词字符串,它运行良好(例如,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;
}
使用
std::getline(std::cin, message);
CIN 只读取到下一个空格,其余的输入保存在流缓冲区中,以便您在第一步中输入的句子的下一个单词作为第二个 CIN 的输入。
相关文章:
- 不断收到相同的错误...怎么了?C++
- 编译器没有显示错误,但我没有得到任何输出.怎么了?
- qsort 不适用于我的 impl 中的浮点类型。怎么了?
- 在C++中表现不佳.怎么了?
- 我的程序怎么了?(C )
- 这里怎么了?单位转换器
- 错误:未定义对 .. 的引用.怎么了
- 我试图编写一个代码来查找一个单词是否是回文,但它不起作用。怎么了?
- 我在C++文件中的简单代码块上有 2 个错误。错误 C2059:语法错误:"?"。第二智能感知:预期表达式。怎么了?
- 我的代码怎么了?带有QT的原始输入API
- 使用 cin.get() 似乎没有读取我期望的字符。怎么了?
- 当其中一个字符串来自cin时,无法比较两个字符串.这里怎么了
- "5"怎么了?纸上一切都很好
- 我的cout怎么了
- C++:腹肌怎么了
- Qt OpenGL with Widgets:怎么了?
- 程序为某些条目提供了错误的输出!怎么了?
- 自动和复制构造函数:怎么了?
- 凯撒密码 - 怎么了?
- 密码程序来掩盖字符 - 怎么了?