[ create a new paste ] login | about

Link: http://codepad.org/IdGEQfgp    [ raw code | output | fork ]

C++, pasted on Mar 8:
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <exception>
#include <iomanip>
using namespace std;

template <typename _CharT>
std::basic_string<_CharT> toHex(const std::basic_string<_CharT>& instr)
{
using namespace std;
basic_ostringstream<_CharT> oss;
oss << hex << setw(sizeof(_CharT)) << setfill(_CharT('0'));
for(typename std::basic_string<_CharT>::const_iterator i = instr.begin(); i != instr.end(); ++i)
{
if(i != instr.begin())
{
oss << ":";
}
//oss << "0x" << static_cast<unsigned short>(*i);
oss << "" << static_cast<unsigned short>(*i);
}
return oss.str();
}

int main()
{
std::wcout << toHex(std::wstring(L"ñ")) << std::endl;
return 0;
}


Output:
1
0000f1


Create a new paste based on this one


Comments: