C++ string for loop to access each character via position index

Description

C++ string for loop to access each character via position index

#include <iostream>
#include <string>
using namespace std;
int main()//from w  w w.  j  a va 2  s . c  o  m
{
   int i;
   string str;
   cout << "Type in any sequence of characters: ";
   getline(cin,str);
   // Cycle through all elements of the string
   for (i = 0; i < int(str.length()); i++)
      str[i] = toupper(str[i]);
   cout << "The characters just entered, in uppercase, are: " << str << endl;
   cin.ignore();
   return 0;
}



PreviousNext

Related