Posts

Showing posts from December, 2014

C++: Type Conversions

typedef std::wstring XSTRING; void Convert(LPCTSTR input, XSTRING &output) { output = input; } void Convert(int input, XSTRING &output) { output = L""; std::wostringstream ws; ws << input; output = XSTRING(ws.str()); } void Convert(unsigned int input, XSTRING &output) { output = L""; std::wostringstream ws; ws << input; output = XSTRING(ws.str()); } void Convert(unsigned long input, XSTRING &output) { output = L""; std::wostringstream ws; ws << input; output = XSTRING(ws.str()); } void Convert(std::string input, XSTRING &output) { output = L""; output = XSTRING(input.begin(), input.end()); } void Convert(XSTRING input, std::string &output) { output = ""; output = std::string(input.begin(), input.end()); } void Convert(char* input, XSTRING &output) { output = L""; output = XSTRING(input, input + strlen(input));