如何使用地图对文本进行编码?
How to encode text using map?
我正在尝试编码hello world文本作为示例。但是在实施过程中有点迷失。
const map<string_view, int64_t> map_hello {
{"h", 199 },{"e", 112 },{"l", 103 },{"o", 109 },{"w", 190 },{"r", 115 },{"d", 162 }
};
我在这里迷路了,我不知道下一步该怎么做,如何比较字符并将数字转移给他们。
string txt = "hello world";
for (auto i : txt) {
cout << i << " result " << endl;
}
您必须使用at()
方法搜索密钥的相应值std::map
int main()
{
const std::map<std::string_view, int64_t> map_hello {
{"hel", 199 },{"lo ", 112 },{"wor", 103 },{"ld!", 109 }
};
std::string txt = "hello world!";
for(int i = 0; i < txt.size(); i += 3) {
auto s1 = txt.substr(i, 3);
std::cout << s1 << std::endl;
auto s2 = map_hello.at(s1);
std::cout << s2 << " result " << std::endl;
}
return 0;
}
相关文章:
- 在CRC-16 CCITT中将数据从二进制解码为文本,我应该输入一个码字,使用CRC生成器进行编码
- 协议缓冲区字符串字段的文本编码
- 如何使用地图对文本进行编码?
- 从文件中读取文本时出现编码问题
- 编码大于原始文本:如何获取零和一的字符串并将它们作为实际字节写入文件
- UTF-16LE 编码问题与 Qt 文本编辑器用 C++ 编写
- 有关读取 UTF-8 编码文本时 Ifstream get() 方法行为的说明 (C++)
- 如何将文本从CP437编码转换为UTF8编码
- C 日食控制台编码纯文本作为其他字符
- UTF8 文本编码 - Windows Phone 8.1 C++
- 如何正确确定文本文件的字符编码
- 为什么我不能在窗口上使用 boost::locale::conv::between 将 UTF-16 文本转换为其他编码
- 字符类型并将 ASCII 文本重新编码为 UTF-16
- 这是怎麽?在读取使用 Unicode 编码的文本文件后控制台输出的开头
- 菜鸟在编码(文本战斗系统)方面存在问题
- 在我的文本编码器程序中找不到错误
- 文本文件编码方案
- Boost:如何检查文本文件字符编码/字符集
- c++中utf -16编码文本的截断读取
- 读取ANSI编码文本作为宽字符串