C++遍历string

来源:互联网 发布:医院排号系统编程 编辑:程序博客网 时间:2024/06/05 16:48

这是我在CSDN上搜索的到的网友的回答

std::string str("hjjlasdfs;lg");int size = str.size();//onefor(int i=0; i < size; ++i) std::cout<<str.at(i) << " ";//twofor(int i=0; i < size; ++i) std::cout<<str[i] << " ";

后来刷leetcode的时候,做到Valid Parentheses这题,有一个遍历string的方法,觉得简洁又新颖,遂记录下来:

string s = "abc";for (char& c : s)     {        cout << c << endl;    }
原创粉丝点击