C ++中的字符串at()函数
在本节中,我们将看到C++中at()函数的含义。该at()方法用于访问给定位置的字符。
在此程序中,我们将使用()函数迭代每个字符,并将它们打印到不同的行中。
范例程式码
#include<iostream>
using namespace std;
main() {
string my_str = "Hello World";
for(int i = 0; i<my_str.length(); i++) {
cout << my_str.at(i) << endl; //get character at position i
}
}输出结果
H e l l o W o r l d
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短