C++ examples for STL:string
Using an iterator to output a string.
#include <iostream> #include <string> int main(int argc, const char* argv[]) { std::string string1("Testing iterators"); std::string::const_iterator iterator1 = string1.begin(); std::cout << "string1 = " << string1 << "\n(using iterator iterator1) string1 is: "; while (iterator1 != string1.end()) { std::cout << *iterator1; // dereference iterator to get char ++iterator1; // advance iterator to next char }//from ww w. java 2 s . c o m std::cout << std::endl; return 0; }