Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::mbsinit

      From cppreference.com
      <cpp‎ |string‎ |multibyte
       
       
       
       
      Defined in header<cwchar>
      int mbsinit(conststd::mbstate_t* ps);

      Ifps is not a null pointer, thembsinit function determines whether the pointed-tostd::mbstate_t object describes the initial conversion state.

      Contents

      [edit]Notes

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

      [edit]Parameters

      ps - pointer to thestd::mbstate_t object to examine

      [edit]Return value

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

      [edit]Example

      Run this code
      #include <clocale>#include <cwchar>#include <iostream>#include <string> int main(){// allow mbrlen() to work with UTF-8 multibyte encodingstd::setlocale(LC_ALL,"en_US.utf8");// UTF-8 narrow multibyte encodingstd::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 initialAfter processing the remaining 2 bytes of 水, the conversion state is initial conversion state

      [edit]See also

      conversion state information necessary to iterate multibyte character strings
      (class)[edit]
      C documentation formbsinit
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/multibyte/mbsinit&oldid=153083"

      [8]ページ先頭

      ©2009-2025 Movatter.jp