basic_string::at
来自cppreference.com
reference at( size_type n ); const_reference at( size_type n ) const;
返回指定位置字符的引用。执行边界检查,无效访问时抛出 /error/exception/out_of_range/ 类型的异常。
目录 |
[编辑] 参数
n - 要返回的字符的位置
[编辑] 返回值
指定字符的引用
[编辑] 例子
#include <string> #include <iostream> int main() { std::string s = "Good news, everyone!"; for (size_t i = 0; i < s.size(); ++i) { std::cout << s.at(i) << std::endl; } }
输出:
Good news, everyone!
[编辑] 复杂度
常量