Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::char_traits<char>::length,std::char_traits<wchar_t>::length,std::char_traits<char8_t>::length,std::char_traits<char16_t>::length,std::char_traits<char32_t>::length

      From cppreference.com
      <cpp‎ |string‎ |char traits
       
       
       
       
      staticstd::size_t length(const char_type* s);
      (constexpr since C++17)

      Returns the length of the character sequence pointed to bys, that is, the position of the terminating null character (char_type()).

      SeeCharTraits for the general requirements on character traits forX::length.

      Contents

      [edit]Parameters

      s - pointer to a character sequence to return length of

      [edit]Return value

      The length of character sequence pointed to bys.

      [edit]Complexity

      Linear.

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <string> void print(constchar* str){std::cout<<std::quoted(str)<<" has length = "<<std::char_traits<char>::length(str)<<'\n';} int main(){    print("foo"); std::string s{"booo"};    print(s.c_str());}

      Output:

      "foo" has length = 3"booo" has length = 4
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/char_traits/length&oldid=158861"

      [8]ページ先頭

      ©2009-2025 Movatter.jp