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++内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复