Hello. What's an easy way to convert from a WCHAR to a string? Thanks!
Printable View
Hello. What's an easy way to convert from a WCHAR to a string? Thanks!
If you mean to convert a wchar_t string to a char string using standard C, then:
If you give more information about why you want to do this, there may be a better way. E.g., you may want to turn off unicode in MSVC++.Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
wchar_t wstr[100] = L"hello world";
char str[50];
wcstombs(str, wstr, 49);
printf("%u: %s\n", strlen(str), str);
return 0;
}