您的位置:首页 > 编程语言

base64code 的一个例子代码

2012-04-05 18:33 302 查看
#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;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息