Home > Back-end >  Why can't C output control characters with the toupper ()?
Why can't C output control characters with the toupper ()?

Time:10-28

Brother just learning c + +, found the following problems:
 # include & lt; Iostream> 
# include & lt; string>
# include & lt; Vector>
# include & lt; Cctype>
using namespace std;
Int main () {
String text="Good mornig!" ;
For (auto it=text. The begin (); it!=text. The end (); + + it) {
Char c=* it;
Coutreturn 0;
}

When the output is like this:
But if the right hand side put toupper:
 c=toupper (c); 
Cout
The normal output;
Why ah?

CodePudding user response:

Because toupper function return value is an int type, so direct output is plastic, but if use c=toupper, int is converted to char types, the output is the character type

CodePudding user response:

You use the
 c=toupper (c); 
is equivalent to implicitly convert an int to the char
  • Related