Monday, 28 December 2015

use of string iterator

// Program to demonstrate the use of string iterator
#include <iostream>
#include <string>

int main()
{
     using namespace std;
     int counter=0;
     string str("welcome to programsplusplus");
     // declares the string iterator
     string::iterator it;
     for (it=str.begin(); it<str.end(); it++)
     {
          // displays each character that the iterator points to
          counter++;
          cout<<" "<<*it;
     }
     cout<<"\n"<<"Total length of the string : "<<counter;

     return 0;
// end of main
------OUTPUT------


Please do comment if you don't understand any part or want to know more or just want to say thanks. I love programming and love to teach my friends. Your suggestions and appreciation will make this blog much better.

No comments:

Post a Comment