将句子转换为C 中的ASCII代码
convert a sentence to ascii code in c++
我想将像'好男孩'这样的句子转换为ASCII代码。我知道循环的代码并打印每个句子每个字符的ASCII代码,但我不想要这个。我希望句子中的ASCII代码(所有字符alltoderth)为例1259788712 ..
您可以使用字符串来处理它。
#include <iostream>
#include <sstream> // use stringstream
using namespace std;
// turn int into string
string IntTOstring(int);
int main(void)
{
string sIn,sOut;
// input
sIn = "good boy";
sOut="";
for (int i=0 ; i<sIn.length() ; i++ ) {
// get one char from sIn each time
int temp=sIn.c_str()[i];
// turn int into string & save in sOut
sOut += IntTOstring(temp);
}
cout << sOut << endl;
return 0;
}
// use stringstream to convert int to string
string IntTOstring(int i){
stringstream ss;
ss << i;
return ss.str();
}
相关文章:
- 如何从 QString 中包含的十六进制值中获取 ASCII 字符?
- 在结构数据类型中更改每个字符的 ASCII 值
- Qt:文件名中的非 ASCII 字符替换为"?"
- 如何与C 字符串中的非ASCII字符一起工作
- 如何在 Boost.Sprit.Qi 中从向量制作组合的 ascii::string 规则<string>?
- 短(ASCII,每个字符 7 位)字符串存储和C++中的比较优化
- 为什么字符数组接受C++中的非 ASCII 字符?
- 将句子转换为C 中的ASCII代码
- 如何从字符中读取ASCII值并将其转换为十六进制格式的字符串
- 处理字符到QString转换中的ASCII字符
- Win32中的任何易于使用的哈希功能都可以放置ASCII字符串
- c 中的ASCII至ISO Latin-1转换
- 如何在C++中读取带有ifstream的替换字符?(ASCII 中的 SUB)
- 将字符串中的所有非 ASCII 字符替换为其等效的 ASCII
- 如何在字符串中插入扩展的ascii字符
- 如何在C 中打印字符串的ASCII代码
- 表中的ASCII值
- c++windows10中的ascii心脏不显示
- 从文件中读取数字并将其存储为十进制而不是c++中的ASCII
- C++ 中 ü 的 ASCii 值