- string[meta header]
- std[meta namespace]
- basic_string[meta class]
- function[meta id-type]
const_reference operator[](size_type pos) const; // (1) C++03
const_reference operator[](size_type pos) const noexcept; // (1) C++11
reference operator[](size_type pos); // (2) C++03
reference operator[](size_type pos) noexcept; // (2) C++11
pos
番目目の要素への参照を取得する。
pos <=
size()
-
C++03
-
C++11以降
投げない
定数時間
#include <iostream>
#include <string>
int main()
{
std::string s = "hello";
char& c = s[1];
std::cout << c << std::endl;
}
- s[1][color ff0000]
e