#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 } }
void print(const std::string &s) { for (std::string::size_type i = 0; i < s.size(); i++) { std::cout << s[i] << ' '; } }
// C++11 for(char& c : str) { do_things_with(c); }