operator[]
描述 (Description)
它返回对字符串中位置pos处的字符的引用。
声明 (Declaration)
以下是std :: string :: operator []的声明
char& operator[] (size_t pos);
C++11
const char& operator[] (size_t pos) const;
参数 (Parameters)
pos - 值与字符串中字符的位置。
返回值 (Return Value)
它返回对字符串中位置pos处的字符的引用。
异常 (Exceptions)
如果抛出异常,则字符串中没有变化。
例子 (Example)
在下面的示例中为std :: string :: operator []。
#include <iostream>
#include <string>
int main () {
std::string str ("Sairamkrishna Mammahe");
for (int i=0; i<str.length(); ++i) {
std::cout << str[i];
}
return 0;
}
Sairamkrishna Mammahe