1#include<iostream>
2using namespace std;
3main() {
4 string my_str = "Hello World";
5 for(int i = 0; i<my_str.length(); i++) {
6 cout << my_str.at(i) << endl; //get character at position i
7 }
8}
1std::string s("Hello world");
2
3for (char & c : s)
4{
5 std::cout << "One character: " << c << "\n";
6 c = '*';
7}
8
1// string::begin/end
2#include <iostream>
3#include <string>
4
5int main ()
6{
7 std::string str ("Test string");
8 for ( std::string::iterator it=str.begin(); it!=str.end(); ++it)
9 std::cout << *it << endl;
10 std::cout << '\n';
11
12 return 0;
13}