erm i got a bit problem with toupper();


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;"input.txt");

        ofstream writefile("out.txt");
            writefile << toupper(ch);

    return 0;


input.txt contains =
"sendy lowercase
sendy halim"

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

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);
This question has already been answered. Start a new discussion instead.