Converts a multibyte character string from the array whose first element is pointed to by src to its wide character representation. Converted characters are stored in the successive elements of the array pointed to by dst. No more than len wide characters are written to the destination array.
Each character is converted as if by a call to std::mbtowc, except that the mbtowc conversion state is unaffected. The conversion stops if:
In most implementations, this function updates a global static object of type std::mbstate_t as it processes through the string, and cannot be called simultaneously by two threads, std::mbsrtowcs should be used in such cases.
POSIX specifies a common extension: if dst is a null pointer, this function returns the number of wide characters that would be written to dst, if converted. Similar behavior is standard for std::mbsrtowcs.
[edit] Parameters dst - pointer to wide character array where the wide string will be stored src - pointer to the first element of a null-terminated multibyte string to convert len - number of wide characters available in the array pointed to by dst [edit] Return valueOn success, returns the number of wide characters, excluding the terminating L'\0', written to the destination array.
On conversion error (if invalid multibyte character was encountered), returns static_cast<std::size_t> (-1).
[edit] Example#include <clocale> #include <cstdlib> #include <iostream> int main() { std::setlocale(LC_ALL, "en_US.utf8"); std::wcout.imbue(std::locale("en_US.utf8")); const char* mbstr = "z\u00df\u6c34\U0001f34c"; // or u8"zÃæ°´ð" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9f\x8d\x8c"; wchar_t wstr[5]; std::mbstowcs(wstr, mbstr, 5); std::wcout << "wide string: " << wstr << '\n'; }
Output:
[edit] See also converts a narrow multibyte character string to wide string, given stateExternT
to InternT
, such as when reading from file
std::codecvt<InternT,ExternT,StateT>
) [edit]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4