wchar_t strings

Discussion about everything. New games, 3d math, development tips...
Post Reply
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

wchar_t strings

Post by Boogle »

I've never worked with these before.. How do I convert a char* to a wchar_t*? Is there anything else I should know about wchar_t strings that might be useful?
Spartacus
Posts: 70
Joined: Fri Nov 21, 2003 11:56 pm

Post by Spartacus »

Well basically, wchar_t is defined as an unsigned short.

Most of the functions, types, and constants listed below are documented in the Run-Time Library Reference, a section of the Visual C++ Programmer's Guide. Those that are not documented there are relatively new to wchar.h and are documented in the topics following this one.
---------------
#define NULL <either 0, 0L, or (void *)0> [0 in C++]
#define WCHAR_MAX <#if expression >= 127>
#define WCHAR_MIN <#if expression <= 0>
#define WEOF <wint_t constant expression>
---------------
wint_t btowc(int c);
wint_t fgetwc(FILE *stream);
wchar_t *fgetws(wchar_t *s, int n, FILE *stream);
wint_t fputwc(wchar_t c, FILE *stream);
int fputws(const wchar_t *s, FILE *stream);
int fwide(FILE *stream, int mode);
int fwprintf(FILE *stream, const wchar_t *format, ...);
int fwscanf(FILE *stream, const wchar_t *format, ...);
wint_t getwc(FILE *stream);
wint_t getwchar(void);
size_t mbrlen(const char *s, size_t n, mbstate_t *ps);
size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
int mbsinit(const mbstate_t *ps);
size_t mbsrtowcs(wchar_t *dst, const char **src, size_t len, mbstate_t *ps);
typedef o-type mbstate_t;
wint_t putwc(wchar_t c, FILE *stream);
wint_t putwchar(wchar_t c);
typedef ui-type size_t;
int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...);
int swscanf(const wchar_t *s, const wchar_t *format, ...);
struct tm;
wint_t ungetwc(wint_t c, FILE *stream);
int vfwprintf(FILE *stream, const wchar_t *format, va_list arg);
int vswprintf(wchar_t *s, size_t n, const wchar_t *format, va_list arg);
int vwprintf(const wchar_t *format, va_list arg);
typedef i-type wchar_t; [keyword in C++]
size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps);
wchar_t *wcscat(wchar_t *s1, const wchar_t *s2);
wchar_t *wcschr(const wchar_t *s, wchar_t c);
int wcscmp(const wchar_t *s1, const wchar_t *s2);
int wcscoll(const wchar_t *s1, const wchar_t *s2);
wchar_t *wcscpy(wchar_t *s1, const wchar_t *s2);
size_t wcscspn(const wchar_t *s1, const wchar_t *s2);
size_t wcsftime(wchar_t *s, size_t maxsize, const wchar_t *format, const struct tm *timeptr);
size_t wcslen(const wchar_t *s);
wchar_t *wcsncat(wchar_t *s1, const wchar_t *s2, size_t n);
int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n);
wchar_t *wcsncpy(wchar_t *s1, const wchar_t *s2, size_t n);
wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2);
wchar_t *wcsrchr(const wchar_t *s, wchar_t c);
size_t wcsrtombs(char *dst, const wchar_t **src, size_t len, mbstate_t *ps);
size_t wcsspn(const wchar_t *s1, const wchar_t *s2);
wchar_t *wcsstr(const wchar_t *s1, const wchar_t *s2);
double wcstod(const wchar_t *nptr, wchar_t **endptr);
wchar_t *wcstok(wchar_t *s1, const wchar_t *s2, wchar_t **ptr);
long wcstol(const wchar_t *nptr, wchar_t **endptr, int base);
unsigned long wcstoul(const wchar_t *nptr, wchar_t **endptr, int base);
size_t wcsxfrm(wchar_t *s1, const wchar_t *s2, size_t n);
int wctob(wint_t c);
typedef i_type wint_t;
wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n); [not in C++]
const wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n); [C++ only]
wchar_t *wmemchr(wchar_t *s, wchar_t c, size_t n); [C++ only]
int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n);
wchar_t *wmemcpy(wchar_t *s1, const wchar_t *s2, size_t n);
wchar_t *wmemmove(wchar_t *s1, const wchar_t *s2, size_t n);
wchar_t *wmemset(wchar_t *s, wchar_t c, size_t n);
int wprintf(const wchar_t *format, ...);
int wscanf(const wchar_t *format, ...);

-----------------------------------------------------------
Include the standard header <wchar.h> so that you can perform input and output operations on wide streams or manipulate wide strings.

If /Zc:wchar_t is not specified, the compiler requires you to either define wchar_t or to include one of the many header files that defines it (ie. wchar.h).

When the /Zc:wchar_t compiler option is specified, the type wchar_t becomes a native type that maps to __wchar_t in the same way that short maps to __int16.

__wchar_t is always available.
By providing overloads for both the unsigned short and __wchar_t variations of wchar_t, you can create libraries that can easily be linked with code compiled with or without /Zc:wchar_t and avoid the need to provide two different builds of the library (one with and one without /Zc:wchar_t enabled).

When /Zc:wchar_t is specified, _WCHAR_T_DEFINED and _NATIVE_WCHAR_T_DEFINED symbols are also defined.
Post Reply