64,654
社区成员
发帖
与我相关
我的任务
分享
//仅以标准库中的string例
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "abcdefg0123456";
string result = "";
char buff[8];
for (int i = 0; i < str.length(); ++i)
result = result + itoa(str[i], buff, 10) + " ";//想要相连的话,直接去掉空格
while (result.length() < 3) result = "0" + result;
cout << result << endl;
for (int j = 0; j < str.length(); ++j)
cout << int(str[j]) << " "; //如果想要把元素要整数的形式访问,直接使用[]就行了
cout << endl;
return 0;
}
CString PrintAscII(CString m_str)
{
CString m_Org;
int nLen = m_str.GetLength();
m_Org.Empty();
for(int i = 0; i < nLen; i++)
{
char ch = m_str.GetAt(i);
char buf[10];
if(ch < 100)
m_Org += "0";
else if(ch < 10)
m_Org += "00";
itoa(ch, buf, 10);
m_Org += buf;
}
return m_Org;
}