我是靠谱客的博主 失眠黑裤,这篇文章主要介绍C++ 遍历字符串(string),现在分享给大家,希望可以做个参考。

c++ 中获取字符串的长度可以使用length 或者size 

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string a = "hello";
    cout<< a.length() <<endl;
    cout<< a.size() <<endl;

    for (int i = 0;i<a.length(); i++)
    {
       cout<< a[i] <<endl; 
    }
     for (int i = 0;i<a.size(); i++)
    {
       cout<< a[i] <<endl; 
    }
    
};

最后

以上就是失眠黑裤最近收集整理的关于C++ 遍历字符串(string)的全部内容,更多相关C++内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部