Display the characters in a string one at a time by using the indexing operator. - C++ STL

C++ examples for STL:string

Description

Display the characters in a string one at a time by using the indexing operator.

Demo Code

#include <iostream>
#include <string>
using namespace std;
int main()//from  ww  w  . j av a2s .c  o m
{
   string str1("Alpha");
   string str2("Beta");
   string str3("Gamma");
   string str4;
   for(unsigned i = 0; i < str1.size(); ++i)
      cout << "str1[i]: " << str1[i] << endl;
   cout << endl;
   return 0;
}

Result


Related Tutorials