C++ string for each loop with auto

Description

C++ string for each loop with auto

#include <iostream> 
#include <string> 

using namespace std; 

int main(int argc, char *argv [])
{   /*w  w w.  j ava2s  .  c  o m*/

        string myString{ "This is my string!" }; 
        for (auto &letter : myString) 
        { 
                letter = 'a'; 
                cout << letter << endl; 
        } 
          
        for (const auto &letter : myString) 
        { 
                cout << letter << endl; 
        } 
        return 0; 
}



PreviousNext

Related