std::char_traits::length - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::char_traits::length

From cppreference.com
< cpp‎ | string‎ | char traits

static std::size_t length( const char_type* s ); |  |

Returns the length of the character sequence pointed to by `s`, that is, the position of the terminating null character (CharT()).

### [edit] Parameters

s | - | pointer to a character sequence to return length of

### [edit] Return value

The length of character sequence pointed to by `s`.

### [edit] Exceptions

(none)

### [edit] Complexity

Linear.

### [edit] Example

Run this code

    #include <iostream>

    void print(const char* str)
    {
      std::cout << "string '" << str << "' ";
      std::cout << "length = " << std::char_traits<char>::length(str) << '\n';
    }

    int main()
    {
      print("foo");

      std::string s("booo");
      print(s.c_str());
    }

Output:

    string 'foo' length = 3
    string 'booo' length = 4

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/string/char_traits/length&oldid=67294"