c++ - tolower() is returning a number instead of a the lowercase form? -


i writing program asks input of letters , and sorts them letter , occurrence based on input. i'm @ end of code , trying convert uppercase letters lowercase. i'm trying this:

cout << tolower(char('a'+i)) << " " << alphabets[i] <<endl; 

but tolower() outputs number instead of lowercase version of letter? example, input "aaaa" gives me :

97 4

and input "bbbbb" gives me:

98 5

but when take out tolower, input "aaa" be:

a 3

i don't understand why happening.

tolower ancient function inherited 1970's-era c, before function signatures reliably existed , before people cared different integer types expressions.

so, ignores types , returns character in int. 3 alternatives:

  1. cast: static_cast< char >( std::tolower( 'a' + ) ).
  2. use variable: char lower = std::tolower( 'a' + );
  3. use newer overload: std::tolower( 'a', std::locale() ).

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -