I have 2 functions here that do almost the same thing. One converts a string to wstring and the other wstring to string. Somehow I think I should create one template function for this but dont see how to do it. Anyone else have an idea on how to do this?
Code:
static std::string wide_to_char(const std::wstring &ws)
{
std::string s;
for (std::string::size_type i = 0; i < ws.length(); i++)
{
char c;
wctomb(&c, ws[i]);
s.push_back(c);
}
return s;
}
static std::wstring char_to_wide(const std::string &s)
{
std::wstring ws;
for (std::string::size_type i = 0; i < s.length(); i++)
{
wchar_t c;
mbtowc(&c, &s[i], 1);
ws.push_back(c);
}
return ws;
}