- string[meta header]
- std[meta namespace]
- basic_string[meta class]
- function[meta id-type]
size_type length() const; // C++03
size_type length() const noexcept; // C++11
文字列の長さを取得する。
現在格納されている文字列の要素数。
※文字数ではないことに注意
投げない
定数時間
#include <iostream>
#include <string>
int main()
{
std::string s = "hello";
std::size_t n = s.length();
std::cout << n << std::endl;
}
- length()[color ff0000]
5