Answers for "iterator over a string c++"

C++
10

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
1

iterating string in cpp

std::string s("Hello world");

for (char & c : s)
{
    std::cout << "One character: " << c << "\n";
    c = '*';
}
Posted by: Guest on May-23-2021

Browse Popular Code Answers by Language