我是靠谱客的博主 欢呼网络,这篇文章主要介绍c++遍历字符串的三种方式,现在分享给大家,希望可以做个参考。

 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream> using namespace std; int main () { string str = "abcdef"; for(unsigned int i = 0; i < str.length(); i++) { cout<<str[i]; //下标访问 } cout<<endl; for(auto c : str) { cout<<c; //范围for语句 } cout<<endl; for(auto iter = str.begin(); iter != str.end(); iter++) { cout<<*iter; //迭代器访问 } cout<<endl; }

 

最后

以上就是欢呼网络最近收集整理的关于c++遍历字符串的三种方式的全部内容,更多相关c++遍历字符串内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部