Answers for "how to iterate in string in c++"

C++
7

how to iterate in string in c++

#include<iostream>
using namespace std;
main() {
   string my_str = "Hello World";
   for(int i = 0; i<my_str.length(); i++) {
      cout << my_str.at(i) << endl; //get character at position i
   }
}
Posted by: Guest on October-24-2020
0

string iterator in c++

// string::begin/end
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Test string");
  for ( std::string::iterator it=str.begin(); it!=str.end(); ++it)
    std::cout << *it << endl;
  std::cout << '\n';

  return 0;
}
Posted by: Guest on November-21-2020

Code answers related to "how to iterate in string in c++"

Browse Popular Code Answers by Language