1char choice;
2// it will instantly transform it to upper case without the need
3// to convert it to int first
4choice = (char)toupper(choice);
5
1std::string data = "This is a sample string.";
2// convert string to upper case
3std::for_each(data.begin(), data.end(), [](char & c){
4c = ::toupper(c);
5});
1int result = toupper(charecterVariable);// return the int that corresponding upper case char
2//if there is none then it will return the int for the original input.
3//can convert int to char after
4char result2 = (char)toupper(variableChar);
1#include <cctype>
2#include <iostream>
3#include <cstring>
4#include <cstdio>
5
6using namespace std;
7
8int main()
9{
10 char str[] = "John is from USA.";
11
12 cout << "The uppercase version of \"" << str << "\" is " << endl;
13
14 for (int i=0; i<strlen(str); i++)
15 putchar(toupper(str[i]));
16
17 return 0;
18}
1// toupper example (C++)
2#include <iostream> // std::cout
3#include <string> // std::string
4#include <locale> // std::locale, std::toupper
5
6int main ()
7{
8 std::locale loc;
9 std::string str="Test String.\n";
10 for (std::string::size_type i=0; i<str.length(); ++i)
11 std::cout << std::toupper(str[i],loc);
12 return 0;
13}
14
15/*
16Output:
17TEST STRING.
18*/