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));
}
void Convert(XSTRING input, long &output)
{
output = 0;
std::wistringstream wstrm(input);
wstrm >> output;
}
void Convert(XSTRING input, unsigned short &output)
{
char tmp[32];
for(int index=0; index<32 br="" index=""> tmp[index]='\0';
}
Convert(input.c_str(),tmp, sizeof(tmp));
output = (unsigned short)atoi(tmp);
}
void Convert(const wchar_t *input, char* output, int size)
{
wcstombs ( output, input, size);
}
void Convert(wchar_t *input, XSTRING &output)
{
output = XSTRING(input);
}32>
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));
}
void Convert(XSTRING input, long &output)
{
output = 0;
std::wistringstream wstrm(input);
wstrm >> output;
}
void Convert(XSTRING input, unsigned short &output)
{
char tmp[32];
for(int index=0; index<32 br="" index=""> tmp[index]='\0';
}
Convert(input.c_str(),tmp, sizeof(tmp));
output = (unsigned short)atoi(tmp);
}
void Convert(const wchar_t *input, char* output, int size)
{
wcstombs ( output, input, size);
}
void Convert(wchar_t *input, XSTRING &output)
{
output = XSTRING(input);
}32>
These compilation of type conversion is very useful. It helped me in my projects very much!
ReplyDelete