erm i got a bit problem with toupper();

example:

char ch = 'a';
char upper;

upper = toupper(ch);

if i use cout to show char "upper", it shows the ascii code for uppercase..
in this case, it shows '65' in screen, i know it supposed to show 'A' instead of '65', how to makes it shows 'A' instead of '65' in the screen?

Can you post a complete program that exhibits the problem? cout should be smart enough to treat chars and strings differently from integer types, so I suspect the snippet given isn't entirely accurate compared to what you're actually testing.

or i try with this one code

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>


using namespace std;

int main()
{
    char ch;


    ifstream readfile;

    readfile.open("input.txt");

    if(readfile)
    {
        ofstream writefile("out.txt");
        while(readfile.get(ch))
        {
            writefile << toupper(ch);
        }
    }

    return 0;

}

input.txt contains =
"sendy lowercase
sendy halim"

after i run the program, the out.txt contains =
"836978688932767987698267658369108369786889327265767377"

seems it contains ASCII codes for all uppercase letter from input.txt..

toupper() both accepts and returns an int to account for EOF. You need to assign that result to a char or cast it before printing:

writefile << (char)toupper(ch);
Comments
nice!
This question has already been answered. Start a new discussion instead.