Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      wcslen, wcsnlen_s

      From cppreference.com
      <c‎ |string‎ |wide
       
       
       
      Null-terminated wide strings
       
      Defined in header<wchar.h>
      size_t wcslen(constwchar_t*str);
      (1)(since C95)
      size_t wcsnlen_s(constwchar_t*str,size_t strsz);
      (2)(since C11)
      1) Returns the length of a wide string, that is the number of non-null wide characters that precede the terminating null wide character.
      2) Same as(1), except that the function returns zero ifstr is a null pointer and returnsstrsz if the null wide character was not found in the firststrsz wide characters ofsrc
      As with all bounds-checked functions,wcslen_s is only guaranteed to be available if__STDC_LIB_EXT1__ is defined by the implementation and if the user defines__STDC_WANT_LIB_EXT1__ to the integer constant1 before including<stdio.h>..

      Contents

      [edit]Parameters

      str - pointer to the null-terminated wide string to be examined
      strsz - maximum number of wide characters to examine

      [edit]Return value

      1) The length of the null-terminated wide stringstr.
      2) The length of the null-terminated wide stringstr on success, zero ifstr is a null pointer,strsz if the null wide character was not found.

      [edit]Notes

      strnlen_s andwcsnlen_s are the onlybounds-checked functions that do not invoke the runtime constraints handler. They are pure utility functions used to provide limited support for non-null terminated strings.

      [edit]Example

      Run this code
      #include <wchar.h>#include <stdio.h> int main(void){wchar_t str[]= L"How many wide characters does this string contain?"; printf("without null character: %zu\n", wcslen(str));printf("with null character: %zu\n",sizeof str/sizeof*str);}

      Output:

      without null character: 50with null character: 51

      [edit]References

      • C11 standard (ISO/IEC 9899:2011):
      • 7.29.4.6.1 The wcslen function (p: 439)
      • K.3.9.2.4.1 The wcsnlen_s function (p: 646-647)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.24.4.6.1 The wcslen function (p: 385)

      [edit]See also

      returns the length of a given string
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/string/wide/wcslen&oldid=101823"

      [8]ページ先頭

      ©2009-2025 Movatter.jp