A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../error/error_code/../../string/multibyte/mbsinit.html below:

std::mbsinit - cppreference.com

If ps is not a null pointer, the mbsinit function determines whether the pointed-to std::mbstate_t object describes the initial conversion state.

[edit] Notes

Although a zero-initialized std::mbstate_t always represents the initial conversion state, there may be other values of std::mbstate_t that also represent the initial conversion state.

[edit] Parameters [edit] Return value

​0​ if ps is not a null pointer and does not represent the initial conversion state, nonzero value otherwise.

[edit] Example
#include <clocale>
#include <cwchar>
#include <iostream>
#include <string>
 
int main()
{
    // allow mbrlen() to work with UTF-8 multibyte encoding
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    std::string str = "æ°´"; // or u8"\u6c34" or "\xe6\xb0\xb4"
    std::mbstate_t mb = std::mbstate_t();
    (void)std::mbrlen(&str[0], 1, &mb);
    if (!std::mbsinit(&mb))
        std::cout << "After processing the first 1 byte of " << str
                  << " the conversion state is not initial\n";
 
    (void)std::mbrlen(&str[1], str.size() - 1, &mb);
    if (std::mbsinit(&mb))
        std::cout << "After processing the remaining 2 bytes of " << str
                  << ", the conversion state is initial conversion state\n";
}

Output:

After processing the first 1 byte of æ°´ the conversion state is not initial
After processing the remaining 2 bytes of æ°´, the conversion state is initial conversion state
[edit] See also

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