c++ char capital letter code example

Example 1: c++ char to uppercase

char choice; 
// it will instantly transform it to upper case without the need
// to convert it to int first
choice = (char)toupper(choice);

Example 2: uppercase capitalise character in string c++

str[i] = toupper(str[i]);

Example 3: touppercase c++

#include <cctype>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
    char str[] = "John is from USA.";

    cout << "The uppercase version of \"" << str << "\" is " << endl;

    for (int i=0; i<strlen(str); i++)
        putchar(toupper(str[i]));
    
    return 0;
}

Tags:

Cpp Example