I am using base64 encoding / decoding from http://www.adp-gmbh.ch/cpp/common/base64.html
This works well with the following code.
const std::string s = "I Am A Big Fat Cat" ; std::string encoded = base64_encode(reinterpret_cast<const unsigned char*>(s.c_str()), s.length()); std::string decoded = base64_decode(encoded); std::cout << _T("encoded: ") << encoded << std::endl; std::cout << _T("decoded: ") << decoded << std::endl;
However, when it comes to unicode
namespace std { #ifdef _UNICODE typedef wstring tstring; #else typedef string tstring; #endif } const std::tstring s = _T("I Am A Big Fat Cat");
How can I use the above function?
Simple change
std::string base64_encode(unsigned TCHAR const* , unsigned int len); std::tstring base64_decode(std::string const& s);
will not work correctly.
(I expect base64_encode to return ASCII. Therefore, std :: string should be used instead of std :: tstring)
source share