Saturday, October 19, 2013

use of char

The program below about using char shows a little about how it works, but actually this is so boring I have skipped most of this stuff.
#include <iostream>

using namespace std;

int main()
{
    char ch = 'M'; //initialize ch as a char and assign M to it
    int i = ch; //store ch - a char - as an integer value
    cout << "the ascii code for i is " << i << endl;
    cout << "add 1 to the character code - i.e. to char ch and then assign to i" << endl;
    ch = ch + 1;
    i = ch;
    cout << "the ascii code for " << ch << " is " << i << endl;

    cout << "lets use cout.put() member function to display a char: " << endl;
    cout.put(ch);
    cout << endl << " and show cout.put() using a character constant " << endl;
    cout.put('X') << endl;
    cout << " done" << endl;
    cout << "note if you use cout.put() on a cout line it gets all messed up - see this - but with no syntax error " << endl;
    cout << "this is funnny " << cout.put(ch) << " funny ehh " << endl;
    return 0;
}

No comments:

Post a Comment