📄 wchar.html
字号:
<HTML><HEAD><TITLE><wchar.h></TITLE></HEAD><BODY><H1><A NAME="<wchar.h>"><CODE><wchar.h></CODE></A></H1><P>[Added with<A HREF="lib_over.html#Amendment 1">Amendment 1</A>]</P><HR><P><B><CODE><A HREF="#NULL">NULL</A>· <A HREF="#WCHAR_MAX">WCHAR_MAX</A>· <A HREF="#WCHAR_MIN">WCHAR_MIN</A>· <A HREF="#WEOF">WEOF</A></CODE></B></P><P><B><CODE><A HREF="#btowc">btowc</A>· <A HREF="#fgetwc">fgetwc</A>· <A HREF="#fgetws">fgetws</A>· <A HREF="#fputwc">fputwc</A>· <A HREF="#fputws">fputws</A>· <A HREF="#fwide">fwide</A>· <A HREF="#fwprintf">fwprintf</A>· <A HREF="#fwscanf">fwscanf</A>· <A HREF="#getwc">getwc</A>· <A HREF="#getwchar">getwchar</A>· <A HREF="#mbrlen">mbrlen</A>· <A HREF="#mbrtowc">mbrtowc</A>· <A HREF="#mbsinit">mbsinit</A>· <A HREF="#mbsrtowcs">mbsrtowcs</A>· <A HREF="#mbstate_t">mbstate_t</A>· <A HREF="#putwc">putwc</A>· <A HREF="#putwchar">putwchar</A>· <A HREF="#size_t">size_t</A>· <A HREF="#swprintf">swprintf</A>· <A HREF="#swscanf">swscanf</A>· <A HREF="#tm">tm</A>· <A HREF="#ungetwc">ungetwc</A>· <A HREF="#vfwprintf">vfwprintf</A>· <A HREF="#vswprintf">vswprintf</A>· <A HREF="#vwprintf">vwprintf</A>· <A HREF="#wchar_t">wchar_t</A>· <A HREF="#wcrtomb">wcrtomb</A>· <A HREF="#wcscat">wcscat</A>· <A HREF="#wcschr">wcschr</A>· <A HREF="#wcscmp">wcscmp</A>· <A HREF="#wcscoll">wcscoll</A>· <A HREF="#wcscpy">wcscpy</A>· <A HREF="#wcscspn">wcscspn</A>· <A HREF="#wcsftime">wcsftime</A>· <A HREF="#wcslen">wcslen</A>· <A HREF="#wcsncat">wcsncat</A>· <A HREF="#wcsncmp">wcsncmp</A>· <A HREF="#wcsncpy">wcsncpy</A>· <A HREF="#wcspbrk">wcspbrk</A>· <A HREF="#wcsrchr">wcsrchr</A>· <A HREF="#wcsrtombs">wcsrtombs</A>· <A HREF="#wcsspn">wcsspn</A>· <A HREF="#wcsstr">wcsstr</A>· <A HREF="#wcstod">wcstod</A>· <A HREF="#wcstok">wcstok</A>· <A HREF="#wcstol">wcstol</A>· <A HREF="#wcstoul">wcstoul</A>· <A HREF="#wcsxfrm">wcsxfrm</A>· <A HREF="#wctob">wctob</A>· <A HREF="#wint_t">wint_t</A>· <A HREF="#wmemchr">wmemchr</A>· <A HREF="#wmemcmp">wmemcmp</A>· <A HREF="#wmemcpy">wmemcpy</A>· <A HREF="#wmemmove">wmemmove</A>· <A HREF="#wmemset">wmemset</A>· <A HREF="#wprintf">wprintf</A>· <A HREF="#wscanf">wscanf</A></CODE></B></P><HR><P>Include the standard header <B><CODE><wchar.h></CODE></B>so that you can perform input and output operations onwide streams or manipulate wide strings.</P><PRE> /* MACROS */#define <A HREF="#NULL"><B>NULL</B></A> <I><either 0, 0L, or (void *)0></I> <B>[0 in C++]</B>#define <A HREF="#WCHAR_MAX"><B>WCHAR_MAX</B></A> <I><#if expression >= 127></I>#define <A HREF="#WCHAR_MIN"><B>WCHAR_MIN</B></A> <I><#if expression <= 0></I>#define <A HREF="#WEOF"><B>WEOF</B></A> <I><</I>wint_t <I>constant expression></I> /* TYPES */typedef <I>o-type</I> <A HREF="#mbstate_t"><B>mbstate_t</B></A>;typedef <I>ui-type</I> <A HREF="#size_t"><B>size_t</B></A>;typedef <I>i-type</I> <A HREF="#wchar_t"><B>wchar_t</B></A>; <B>[keyword in C++]</B>typedef <I>i_type</I> <A HREF="#wint_t"><B>wint_t</B></A>;struct <A HREF="#tm"><B>tm</B></A>; /* FUNCTIONS */wint_t <A HREF="#fgetwc"><B>fgetwc</B></A>(FILE *stream);wchar_t *<A HREF="#fgetws"><B>fgetws</B></A>(wchar_t *s, int n, FILE *stream);wint_t <A HREF="#fputwc"><B>fputwc</B></A>(wchar_t c, FILE *stream);int <A HREF="#fputws"><B>fputws</B></A>(const wchar_t *s, FILE *stream);int <A HREF="#fwide"><B>fwide</B></A>(FILE *stream, int mode);wint_t <A HREF="#getwc"><B>getwc</B></A>(FILE *stream);wint_t <A HREF="#getwchar"><B>getwchar</B></A>(void);wint_t <A HREF="#putwc"><B>putwc</B></A>(wchar_t c, FILE *stream);wint_t <A HREF="#putwchar"><B>putwchar</B></A>(wchar_t c);wint_t <A HREF="#ungetwc"><B>ungetwc</B></A>(wint_t c, FILE *stream);int <A HREF="#fwscanf"><B>fwscanf</B></A>(FILE *stream, const wchar_t *format, ...);int <A HREF="#swscanf"><B>swscanf</B></A>(const wchar_t *s, const wchar_t *format, ...);int <A HREF="#wscanf"><B>wscanf</B></A>(const wchar_t *format, ...);int <A HREF="#fwprintf"><B>fwprintf</B></A>(FILE *stream, const wchar_t *format, ...);int <A HREF="#swprintf"><B>swprintf</B></A>(wchar_t *s, size_t n, const wchar_t *format, ...);int <A HREF="#wprintf"><B>wprintf</B></A>(const wchar_t *format, ...);int <A HREF="#vfwprintf"><B>vfwprintf</B></A>(FILE *stream, const wchar_t *format, va_list arg);int <A HREF="#vswprintf"><B>vswprintf</B></A>(wchar_t *s, size_t n, const wchar_t *format, va_list arg);int <A HREF="#vwprintf"><B>vwprintf</B></A>(const wchar_t *format, va_list arg);size_t <A HREF="#wcsftime"><B>wcsftime</B></A>(wchar_t *s, size_t maxsize, const wchar_t *format, const struct tm *timeptr);wint_t <A HREF="#btowc"><B>btowc</B></A>(int c);size_t <A HREF="#mbrlen"><B>mbrlen</B></A>(const char *s, size_t n, mbstate_t *ps);size_t <A HREF="#mbrtowc"><B>mbrtowc</B></A>(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);int <A HREF="#mbsinit"><B>mbsinit</B></A>(const mbstate_t *ps);size_t <A HREF="#mbsrtowcs"><B>mbsrtowcs</B></A>(wchar_t *dst, const char **src, size_t len, mbstate_t *ps);size_t <A HREF="#wcrtomb"><B>wcrtomb</B></A>(char *s, wchar_t wc, mbstate_t *ps);size_t <A HREF="#wcsrtombs"><B>wcsrtombs</B></A>(char *dst, const wchar_t **src, size_t len, mbstate_t *ps);double <A HREF="#wcstod"><B>wcstod</B></A>(const wchar_t *nptr, wchar_t **endptr);long <A HREF="#wcstol"><B>wcstol</B></A>(const wchar_t *nptr, wchar_t **endptr, int base);unsigned long <A HREF="#wcstoul"><B>wcstoul</B></A>(const wchar_t *nptr, wchar_t **endptr, int base);int <A HREF="#wctob"><B>wctob</B></A>(wint_t c);wchar_t *<A HREF="#wcscat"><B>wcscat</B></A>(wchar_t *s1, const wchar_t *s2);int <A HREF="#wcscmp"><B>wcscmp</B></A>(const wchar_t *s1, const wchar_t *s2);int <A HREF="#wcscoll"><B>wcscoll</B></A>(const wchar_t *s1, const wchar_t *s2);wchar_t *<A HREF="#wcscpy"><B>wcscpy</B></A>(wchar_t *s1, const wchar_t *s2);size_t <A HREF="#wcscspn"><B>wcscspn</B></A>(const wchar_t *s1, const wchar_t *s2);size_t <A HREF="#wcslen"><B>wcslen</B></A>(const wchar_t *s);wchar_t *<A HREF="#wcsncat"><B>wcsncat</B></A>(wchar_t *s1, const wchar_t *s2, size_t n);int <A HREF="#wcsncmp"><B>wcsncmp</B></A>(const wchar_t *s1, const wchar_t *s2, size_t n);wchar_t *<A HREF="#wcsncpy"><B>wcsncpy</B></A>(wchar_t *s1, const wchar_t *s2, size_t n);size_t <A HREF="#wcsspn"><B>wcsspn</B></A>(const wchar_t *s1, const wchar_t *s2);wchar_t *<A HREF="#wcsstr"><B>wcsstr</B></A>(const wchar_t *s1, const wchar_t *s2);wchar_t *<A HREF="#wcstok"><B>wcstok</B></A>(wchar_t *s1, const wchar_t *s2, wchar_t **ptr);size_t <A HREF="#wcsxfrm"><B>wcsxfrm</B></A>(wchar_t *s1, const wchar_t *s2, size_t n);int <A HREF="#wmemcmp"><B>wmemcmp</B></A>(const wchar_t *s1, const wchar_t *s2, size_t n);wchar_t *<A HREF="#wmemcpy"><B>wmemcpy</B></A>(wchar_t *s1, const wchar_t *s2, size_t n);wchar_t *<A HREF="#wmemmove"><B>wmemmove</B></A>(wchar_t *s1, const wchar_t *s2, size_t n);wchar_t *<A HREF="#wmemset"><B>wmemset</B></A>(wchar_t *s, wchar_t c, size_t n);wchar_t *<A HREF="#wcschr"><B>wcschr</B></A>(const wchar_t *s, wchar_t c); <B>[not in C++]</B>const wchar_t *<A HREF="#wcschr"><B>wcschr</B></A>(const wchar_t *s, wchar_t c); <B>[C++ only]</B>wchar_t *<A HREF="#wcschr"><B>wcschr</B></A>(wchar_t *s, wchar_t c); <B>[C++ only]</B>wchar_t *<A HREF="#wcspbrk"><B>wcspbrk</B></A>(const wchar_t *s1, const wchar_t *s2); <B>[not in C++]</B>const wchar_t *<A HREF="#wcspbrk"><B>wcspbrk</B></A>(const wchar_t *s1, const wchar_t *s2); <B>[C++ only]</B>wchar_t *<A HREF="#wcspbrk"><B>wcspbrk</B></A>(wchar_t *s1, const wchar_t *s2); <B>[C++ only]</B>wchar_t *<A HREF="#wcsrchr"><B>wcsrchr</B></A>(const wchar_t *s, wchar_t c); <B>[not in C++]</B>const wchar_t *<A HREF="#wcsrchr"><B>wcsrchr</B></A>(const wchar_t *s, wchar_t c); <B>[C++ only]</B>wchar_t *<A HREF="#wcsrchr"><B>wcsrchr</B></A>(wchar_t *s, wchar_t c); <B>[C++ only]</B>wchar_t *<A HREF="#wcsstr"><B>wcsstr</B></A>(const wchar_t *s1, const wchar_t *s2); <B>[not in C++]</B>const wchar_t *<A HREF="#wcsstr"><B>wcsstr</B></A>(const wchar_t *s1, const wchar_t *s2); <B>[C++ only]</B>wchar_t *<A HREF="#wcsstr"><B>wcsstr</B></A>(wchar_t *s1, const wchar_t *s2); <B>[C++ only]</B>wchar_t *<A HREF="#wmemchr"><B>wmemchr</B></A>(const wchar_t *s, wchar_t c, size_t n); <B>[not in C++]</B>const wchar_t *<A HREF="#wmemchr"><B>wmemchr</B></A>(const wchar_t *s, wchar_t c, size_t n); <B>[C++ only]</B>wchar_t *<A HREF="#wmemchr"><B>wmemchr</B></A>(wchar_t *s, wchar_t c, size_t n); <B>[C++ only]</B></PRE><H2><A NAME="btowc"><CODE>btowc</CODE></A></H2><PRE>wint_t <B>btowc</B>(int c);</PRE><P>The function returns<A HREF="#WEOF"><CODE>WEOF</CODE></A> if <CODE>c</CODE> equals<A HREF="stdio.html#EOF"><CODE>EOF</CODE></A>.Otherwise, it converts <CODE>(unsigned char)c</CODE>as a one-byte multibyte character beginning in the<A HREF="charset.html#initial conversion state">initial conversion state</A>,as if by calling<A HREF="#mbrtowc"><CODE>mbrtowc</CODE></A>.If the conversion succeeds, the function returns the wide-characterconversion. Otherwise, it returns<A HREF="#WEOF"><CODE>WEOF</CODE></A>.</P><H2><A NAME="fgetwc"><CODE>fgetwc</CODE></A></H2><PRE>wint_t <B>fgetwc</B>(FILE *stream);</PRE><P>The function reads the next wide character <CODE>c</CODE> (if present)from the input stream <CODE>stream</CODE>,advances the file-position indicator (if defined), and returns<CODE>(<A HREF="#wint_t">wint_t</A>)c</CODE>.If the function sets either the end-of-file indicatoror the error indicator, it returns<A HREF="#WEOF"><CODE>WEOF</CODE></A>.</P><H2><A NAME="fgetws"><CODE>fgetws</CODE></A></H2><PRE>wchar_t *<B>fgetws</B>(wchar_t *s, int n, FILE *stream);</PRE><P>The function reads wide charactersfrom the input stream <CODE>stream</CODE>and stores them in successive elements of the arraybeginning at <CODE>s</CODE> and continuing until it stores<CODE>n - 1</CODE> wide characters, stores an <CODE><I>NL</I></CODE>wide character, or sets the end-of-file or error indicators. If<CODE>fgetws</CODE> stores any wide characters, it concludes by storinga null wide character in the next element of the array. It returns<CODE>s</CODE> if it stores any wide characters and it has not set the errorindicator for the stream; otherwise, it returns a null pointer. Ifit sets the error indicator, the array contents are indeterminate.</P><H2><A NAME="fputwc"><CODE>fputwc</CODE></A></H2><PRE>wint_t <B>fputwc</B>(wchar_t c, FILE *stream);</PRE><P>The function writes the wide character <CODE>c</CODE> to the outputstream <CODE>stream</CODE>, advances the file-position indicator(if defined), and returns<CODE>(<A HREF="#wint_t">wint_t</A>)c</CODE>.If the function sets the error indicator for the stream, it returns<A HREF="#WEOF"><CODE>WEOF</CODE></A>.</P><H2><A NAME="fputws"><CODE>fputws</CODE></A></H2><PRE>int <B>fputws</B>(const wchar_t *s, FILE *stream);</PRE><P>The function accesses wide characters from the string <CODE>s</CODE>and writes them to the output stream <CODE>stream</CODE>. The function doesnot write the terminating null wide character. It returns a nonnegativevalue if it has not set the error indicator; otherwise, it returns<A HREF="#WEOF"><CODE>WEOF</CODE></A>.</P><H2><A NAME="fwide"><CODE>fwide</CODE></A></H2><PRE>int <B>fwide</B>(FILE *stream, int mode);</PRE><P>The function determines the orientation of the stream <CODE>stream</CODE>.If <CODE>mode</CODE> is greater than zero,it first attempts to make the stream<A HREF="lib_file.html#wide oriented">wide oriented</A>.If <CODE>mode</CODE> is less than zero,it first attempts to make the stream<A HREF="lib_file.html#byte oriented">byte oriented</A>.In any event, the function returns:</P><UL><LI>a value greater than zero if the stream is left<A HREF="lib_file.html#wide oriented">wide oriented</A><LI>zero if the stream is left<A HREF="lib_file.html#unbound stream">unbound</A><LI>a value less than zero if the stream is left<A HREF="lib_file.html#byte oriented">byte oriented</A></UL><P>In no event will the function alter the orientation of a streamonce it has been oriented.</P><H2><A NAME="fwprintf"><CODE>fwprintf</CODE></A></H2><PRE>int <B>fwprintf</B>(FILE *stream, const wchar_t *format, ...);</PRE><P>The function<A HREF="lib_prin.html#Print Functions">generates formatted text</A>,under the control of the format <CODE>format</CODE>and any additional arguments, and writeseach generated wide character to the stream <CODE>stream</CODE>. It returnsthe number of wide characters generated, or it returns a negativevalue if the function sets the error indicator for the stream.</P><H2><A NAME="fwscanf"><CODE>fwscanf</CODE></A></H2><PRE>int <B>fwscanf</B>(FILE *stream, const wchar_t *format, ...);</PRE><P>The function<A HREF="lib_scan.html#Scan Functions">scans formatted text</A>,under the control of the format <CODE>format</CODE>and any additional arguments. It obtains eachscanned character from the stream <CODE>stream</CODE>. It returns the numberof input items matched and assigned, or it returns<A HREF="stdio.html#EOF"><CODE>EOF</CODE></A> if thefunction does not store values before it sets the end-of-file or errorindicator for the stream.</P><H2><A NAME="getwc"><CODE>getwc</CODE></A></H2><PRE>wint_t <B>getwc</B>(FILE *stream);</PRE><P>The function has the same effect as<CODE><A HREF="#fgetwc">fgetwc</A>(stream)</CODE> exceptthat a macro version of <CODE>getwc</CODE> can evaluate<CODE>stream</CODE> more than once.</P><H2><A NAME="getwchar"><CODE>getwchar</CODE></A></H2><PRE>wint_t <B>getwchar</B>(void);</PRE><P>The function has the same effect as<CODE><A HREF="#fgetwc">fgetwc</A>(stdin)</CODE>.</P><H2><A NAME="mbrlen"><CODE>mbrlen</CODE></A></H2><PRE>size_t <B>mbrlen</B>(const char *s, size_t n, mbstate_t *ps);</PRE><P>The function is equivalent to the call:</P><PRE><A HREF="#mbrtowc">mbrtowc</A>(0, s, n, ps != 0 ? ps : &internal)</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -