这些简单的转换是用的比较频繁的, 因此将这些功能全部封装在一个类中

头文件

 1 #pragma once
 2 #include <stdlib.h>
 3 #include <string>
 4 #include "tchar.h"
 5 #include "windows.h"
 6 using namespace std;
 7 enum TRANSFORM
 8 {
 9     SINGLECHAR, //单字节转换    eg:0x2121 => 33 33
10     ALLCHAR,    //所有字节转换  eg:0x2121 => 8481
11 };
12 class Transform
13 {
14 public:
15     Transform(void);
16     ~Transform(void);
17 
18 public:
19     string HexStrToAsciiStr(string strValue);
20     string AsciiStrToHexStr(string strValue);
21     string HexToDescInt(string strVaule, TRANSFORM);
22     string DescIntToHex(string strValue);
23     string TCharToString(TCHAR* TValue);
24     void StringToTChar(string strValue, TCHAR* DestTchar);
25 private:
26     string strRepalce(string& strValue, string strSrc, string strDest);
27 };
View Code

相关文章: