public member function
<locale>

std::ctype::toupper

single character (1)
       char_type toupper (char_type c) const;
sequence (2)
const char_type* toupper (char_type* low, const char_type* high) const;
Convert to uppercase
The first version (1) returns the uppercase equivalent of c. If no such equivalent character exists, the value returned is c, unchanged.

The second version (2) replaces any lowercase characters in the range [low,high) with its uppercase equivalent.

Internally, this function simply calls the virtual protected member do_toupper, which does the above by default in both the generic template and the char specialization (ctype<char>).

A non-member function with the same name (toupper) exists with the same behavior as (1).

Parameters

c
Character to convert case.
Member type char_type is the facet's character type (defined as an alias of ctype's template parameter, charT).
low, high
Pointer to the beginning and end of the sequence of characters. The range used is [low,high), which contains all the characters between low and high, including the character pointed by low but not the character pointed by high.
Note that null characters (if any) are also considered, and the function proceeds beyond them, until the entire range is converted.
Member type char_type is the facet's character type (defined as an alias of ctype's template parameter, charT).

Return value

The first version (1) returns the uppercase equivalent of c (or c unchanged if no uppercase equivalent exists).

The second version always returns high.

Member type char_type is the facet's character type (defined as an alias of ctype's template parameter, charT).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// ctype::toupper example
#include <iostream>       // std::cout
#include <locale>         // std::locale, std::ctype, std::use_facet

int main ()
{
  std::locale loc;

  char site[] = "cplusplus.com";

  std::cout << "The first letter of " << site << " as an uppercase is: ";
  std::cout << std::use_facet< std::ctype<char> >(loc).toupper(*site);
  std::cout << '\n';

  std::cout << "The result of converting " << site << " to uppercase is: ";
  std::use_facet< std::ctype<char> >(loc).toupper ( site, site+sizeof(site) );
  std::cout << site << '\n';

  return 0;
}

Output:

The first letter of cplusplus.com as an uppercase is: C
The result of converting cplusplus.com to uppercase is: CPLUSPLUS.COM


Data races

The object is accessed.
In (2), the elements in the range [low,high) are accessed and modified.

Exception safety

If an exception is thrown, there are no changes in the facet object, although characters in the range (2) may have been affected.

See also