Need help with toupper()

The book just went over what toupper did, which was capitalize letters. It didnt show an example of how to use them(this was during the beginning of the book). Im almost done with the book with only 1 chapter left, and it still hasnt gone over how to use toupper, and I feel like it might be important to know.

Ive tried using different codes to make it work. This was the only one that worked.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main()
{
char d = 'a';
cout << toupper(d);
}


It works, but instead of putting "A", it puts "65" in the output. Please explain why it does this, and how to use toupper.
Last edited on
That's because toupper returns an int and cout dutifully output that int.

1
2
3
  char d = 'a';
  d = (char)toupper(d);
  cout << d;


cout << (char)toupper(d);
So, why does a = 65 in programming? Do programmers use toupper a lot? And is toupper important?
Topic archived. No new replies allowed.