#include "stdafx.h"
#include <string>
#include <iostream>
#include <vector>
#include <atlenc.h>
struct CartoonInfo
{
std::wstring strInfo;
};
typedef std::vector<CartoonInfo> VEC_CI;
VEC_CI g_vci;
void AddInfo(LPCWSTR info)
{
CartoonInfo ci;
ci.strInfo = info;
g_vci.push_back(ci);
}
int _tmain(int argc, _TCHAR* argv[])
{
LPCWSTR srcInfo = L"123";
std::string strSrc = (LPCSTR)CW2A(srcInfo);
int nSrcLen = strSrc.length()*2;
char *pDstInfo = new char[nSrcLen*2];
memset(pDstInfo, 0, nSrcLen*2);
int nDstLen = nSrcLen*2;
ATL::Base64Encode((BYTE*)strSrc.c_str(), nSrcLen, pDstInfo, &nDstLen);
AddInfo(CA2W(pDstInfo));
delete[] pDstInfo;
pDstInfo = NULL;
VEC_CI::iterator iter = g_vci.begin();
for(;iter!=g_vci.end(); ++iter)
{
long nSrcSize = (*iter).strInfo.size();
BYTE *pDecodeStr = new BYTE[nSrcSize];
memset(pDecodeStr, 0, nSrcSize);
int nLen = 100;
ATL::Base64Decode(CW2A((*iter).strInfo.c_str()), nSrcSize, pDecodeStr, &nLen);
std::wcout<<(char*)pDecodeStr<<std::endl;
delete[] pDecodeStr;
pDecodeStr = NULL;
}
return 0;
}
本文介绍了一个使用C++实现Base64编码和解码的示例程序。该程序首先将一段文本编码为Base64格式,然后将其存储在结构体中,并再次从结构体中读取进行解码,最终输出原始字符串。文中还涉及了宽字符与普通字符之间的转换。
1809

被折叠的 条评论
为什么被折叠?



