C++ 中的 string at() 函数\n
在本节中,我们将了解 C++ 中的 at() 函数。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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP