Hello. What's an easy way to convert from a WCHAR to a string? Thanks!
This is a discussion on Simple way to convert from a WCHAR to a string? within the C++ Programming forums, part of the General Programming Boards category; Hello. What's an easy way to convert from a WCHAR to a string? Thanks!...
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; }
The human mind treats a new idea the way the body treats a strange protein; it rejects it. - P.B.Medawar