c++ - 试图移动字符串中的每一位
问题描述
尝试一个编码程序,它将转换字符串中每个字符中的 ascii 代码并打印出新字符,以便稍后我可以向左移动并解码消息。
例子
"#" = 35 或 100011
100011 左移一次 = 1000110 或 70
然后我想打印“F”。
到目前为止,这就是我所拥有的代码。我不明白输出。不知道是不是因为没有超过 127 的 ascii 字符的代码。
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int i;
string str ("Hello World");
string encode, decode;
for ( i=0; i<str.length(); ++i)
{
cout << str[i];
}
cout << endl << endl;
for ( i=0; i<str.length(); ++i)
{
cout << (int) str[i] << " ";
}
cout << endl << endl;
for ( i=0; i<str.length(); ++i)
{
encode[i] = (str[i] << 1) ;
cout << encode[i] << " ";
}
cout << endl << endl;
return 0;
}
输出:
Hello World
72 101 108 108 111 32 87 111 114 108 100
\220 \312 \330 \330 \336 @ \256 \336 \344 \330 \310
解决方案
推荐阅读
- python - DictReader 没有以正确的方式解析我的字符串
- android - 有没有办法在 android 模拟器上使用 Microsoft Authenticator 的无密码登录选项
- javascript - Google 表格图表仅返回我的 REST API 的一行
- android - 如何在回收站视图中为多按钮设置 onclick
- moodle - R/exams Moodle 选择题不计分
- azure - 搜索 Azure Runbook 作业的“输入”?
- python - 根据另一个数组中的值从一个数组创建多个数组 - python
- octave - 八度函数
- reactjs - 反应引导打开所有崩溃
- rest - 使用 JWT access_token 和刷新令牌方法保护 REST API