#include <iostream>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {

//string str("abcdefg");
string str = "abcdefg";
//string str2 = str;
string str2(str);
//数组形式遍历
for (int i = 0; i < str.length(); i++) {
cout << str[i] << endl;
}

//at方法遍历
for (int i = 0; i < str.length(); i++) {
cout << str.at(i) << endl;
}

//迭代器遍历
for (string::iterator it = str.begin(); it != str.end(); it++) {
cout << *it << endl;
}
return 0;
}

相关文章:

  • 2021-06-30
  • 2021-07-30
  • 2021-11-28
  • 2022-02-20
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2022-03-08
  • 2022-02-07
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
相关资源
相似解决方案