Use toupper function to convert all elements in a char vector to upper case : vector indexer « Vector « C++






Use toupper function to convert all elements in a char vector to upper case

   
 

#include <iostream>
#include <vector>
#include <cctype>
using namespace std;

int main()
{
  vector<char> v(10); // create a vector of length 10

  cout << "Size = " << v.size() << endl;

  for(int i=0; i<10; i++) 
     v[i] = i + 'a';

  cout << "Current Contents:\n";
  for(int i=0; i<v.size(); i++) cout << v[i] << " ";
  cout << "\n\n";
  
  for(int i=0; i<v.size(); i++) 
     v[i] = toupper(v[i]);
  cout << "Modified Contents:\n";
  for(int i=0; i<v.size(); i++) 
     cout << v[i] << " ";
  cout << endl;

  return 0;
}

/* 
Size = 10
Current Contents:
a b c d e f g h i j

Modified Contents:
A B C D E F G H I J

 */        
    
    
  








Related examples in the same category

1.Use indexer to update element in the vector
2.make the index of the maximum
3.Fill in vector with array by using pointer and offset