Well.. such a conversion would only make sense if your WCHAR string only consisted of characters that can also be represented using CHAR. In that case, yiu can write a conversion function:
Now, you can perform the conversion using std::transform():Code:CHAR wide_to_narrow(WCHAR w) { // simple typecast // works because UNICODE incorporates ASCII into itself return CHAR(w); }
Or, even better, use wstring and string instead of WCHAR and CHAR arrays:Code:WCHAR[20] wstr = "blahblahandmoreblah"; CHAR[20] dest; std::transform(wstr, wstr + 20, dest, wide_to_narrow);
Simple isn't it?Code:std::wstring wstr = "blahblahandmoreblah"; std::string dest(wstr.length()); std::transform(wstr.begin(), wstr.end(), dest.begin(), wide_to_narrow);




Reply With Quote