Partager via


char_traits::length

Returns the length of a string.

static size_t length(
   const char_type* _Str
);

Parameters

  • _Str
    The C-string whose length is to be measured.

Return Value

The number of elements in the sequence being measured, not including the null terminator.

Example

// char_traits_length.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;
   const char* str1= "Hello";
   cout << "The C-string str1 is: " << str1 << endl;
 
   size_t lenStr1;
   lenStr1 = char_traits<char>::length ( str1 );
   cout << "The length of C-string str1 is: " 
        << lenStr1 << "." << endl;
}

The C-string str1 is: Hello
The length of C-string str1 is: 5.

Requirements

Header: <string>

Namespace: std

See Also

Concepts

char_traits Struct

char_traits Members