GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::mbstowcs(3) C++ Standard Libary std::mbstowcs(3)

std::mbstowcs - std::mbstowcs


Defined in header <cstdlib>
std::size_t mbstowcs( wchar_t* dst, const char* src, std::size_t len);


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:


* The multibyte null character was converted and stored.
* An invalid (in the current C locale) multibyte character was encountered.
* The next wide character to be stored would exceed len.


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.


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


On 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).

// Run this code


#include <iostream>
#include <clocale>
#include <cstdlib>
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';
}


wide string: zß水🍌


mbsrtowcs converts a narrow multibyte character string to wide string, given state
(function)
wcstombs converts a wide string to narrow multibyte character string
(function)
do_in converts a string from externT to internT, such as when reading from file
[virtual] (virtual protected member function of std::codecvt<InternT,ExternT,State>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.