「cpp/string/basic string/at」の版間の差分
提供: cppreference.com
< cpp | string | basic string
細 (Fix some translations) |
|||
1行: | 1行: | ||
− | |||
{{cpp/string/basic_string/title | at}} | {{cpp/string/basic_string/title | at}} | ||
{{cpp/string/basic_string/navbar}} | {{cpp/string/basic_string/navbar}} | ||
11行: | 10行: | ||
{{dcl end}} | {{dcl end}} | ||
− | 指定された位置{{tt|pos}} | + | 指定された位置 {{tt|pos}} {{lc|std::out_of_range}} |
− | === | + | ====== |
{{par begin}} | {{par begin}} | ||
− | {{par | pos | | + | {{par | pos | }} |
{{par end}} | {{par end}} | ||
− | === | + | ====== |
− | + | ||
===例外=== | ===例外=== | ||
− | {{c|1=pos >= size()}}の場合{{lc|std::out_of_range}} | + | {{c|1=pos >= size()}} の場合 {{lc|std::out_of_range}} |
===計算量=== | ===計算量=== | ||
− | + | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
− | |||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc inc | cpp/string/basic_string/dsc operator_at }} | {{dsc inc | cpp/string/basic_string/dsc operator_at }} |
2018年3月27日 (火) 07:20時点における版
reference at( size_type pos ); |
||
const_reference at( size_type pos ) const; |
||
指定された位置 pos
の文字を指す参照を返します。 範囲チェックが行われ、無効なアクセスの場合 std::out_of_range 型の例外が投げられます。
目次 |
引数
pos | - | 返す文字の位置 |
戻り値
要求された文字を指す参照。
例外
pos >= size() の場合 std::out_of_range を投げます。
計算量
一定。
例
Run this code
#include <stdexcept> #include <iostream> #include <string> int main() { std::string s("message"); // for capacity s = "abc"; s.at(2) = 'x'; // ok std::cout << s << '\n'; std::cout << "string size = " << s.size() << '\n'; std::cout << "string capacity = " << s.capacity() << '\n'; try { // throw, even if capacity allowed to access element s.at(3) = 'x'; } catch (std::out_of_range const& exc) { std::cout << exc.what() << '\n'; } }
出力:
abx string size = 3 string capacity = 7 basic_string::at
関連項目
指定された文字にアクセスします (パブリックメンバ関数) |