#include <iostream>
#include <string>
using namespace std;
string dump_block(const char* aInStr,int len)
{
const char HEX[] = "0123456789ABCDEF";
std::string lStr;
for(int i=0; i < len; i++)
{
char lTemp = aInStr[i];
lStr.push_back(HEX[lTemp/16]);
lStr.push_back(HEX[lTemp%16]);
}
return lStr;
}
int main()
{
string lStr("WeAreBusy");
cout << dump_block(lStr.c_str(),lStr.size()) << endl;
}
参考网上代码,这样写不会有神马内存泄露问题,算是小改进吧,不过神马也不是。
char*转化为hex string输出
最新推荐文章于 2024-03-04 16:46:19 发布