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!

[编辑] 复杂度

常量

[编辑] 参见

operator[]

个人工具
名字空间
操作
导航
工具箱
其他语言