Contents

2. Usage of mychar class

The mychar class is a complete replacement for char and char * datatype. You can use mychar class just like char and get much more functionalities. See illustration code as given below -


        mychar aa;

        aa = " Washington DC is capital of USA ";

        // You can use aa.val like a 'char *' variable in programs !!
        for (unsigned long tmpii = 0; tmpii < aa.length(); tmpii++)
        {
                fprintf(stdout, "aa.val[%ld]=%c ", tmpii, aa.val[tmpii]);
        }

        // Using pointers on 'char *' val ...
        for (; *aa.val != 0; aa.val++)
        {
                fprintf(stdout, "aa.val=%c ", *aa.val);
        }

A complete example program "mychar.cpp" implementing the mychar class is given in Appendix A and mychar class is given in Appendix B.

2.1 Operators

The mychar class provides these operators :-

For example to use operators -
        mychar aa;

        aa = "put some value string";
        aa += "add some more";
        aa = "My name is" + " Alavoor Vasudevan ";

        if (aa == "some string")
                cout << "strings are equal" << endl;

        if (aa != "some string") 
                cout << "strings are not equal" << endl;

2.2 Functions

The mychar class provides these functions :-

2.3 Miscellaneous Functions

Some miscellaneous mychar functions are given here, but DO NOT USE these, and instead use operators like '+', '+=', '==' etc..

For example to convert integer to string do -
        mychar  aa;

        aa = 34;  // The '=' operator will convert int to string
        cout << "The value of aa is : " << aa.val << endl;

        aa = 234.878;  // The '=' operator will convert float to string
        cout << "The value of aa is : " << aa.val << endl;

        aa = 34 + 234.878;
        cout << "The value of aa is : " << aa.val << endl;
        // The output aa will be '268.878'

        // You must cast mychar to convert
        aa = (mychar) 34 + " Honourable President Ronald Reagan " + 234.878;
        cout << "The value of aa is : " << aa.val << endl;
        // The output aa will be '34 Honourable President Ronald Reagan 234.878'


Contents