Using auto with Standard for Loops on string value - C++ STL

C++ examples for STL:string

Description

Using auto with Standard for Loops on string value

Demo Code

#include <iostream> 
#include <string> 

using namespace std; 

int main(int argc, char *argv [])
{   //from  ww w . ja va  2 s  .co m

        string myString{ "This is my string!" }; 

        for (auto iter = myString.begin(); iter != myString.end(); ++iter) 
        { 
                cout << *iter << endl; 
        } 
          
        for (auto iter = myString.cbegin(); iter != myString.cend(); ++iter) 
        { 
                cout << *iter << endl; 
        } 
        return 0; 
}

Result


Related Tutorials