Use for loop to access each character in string one by one and use position index - C++ STL

C++ examples for STL:string

Description

Use for loop to access each character in string one by one and use position index

Demo Code

#include <iostream>
#include <string>
using namespace std;
int main()//from  w w w .ja v  a 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;
}

Result


Related Tutorials