Why is it that everything works with characters except multiplication (well multiplication works if you divide first...but that's not what I want)
here is the code example:
int main()
{
char ch = 'B';
std::cout << "Int of \'B\' " << (int) ch << " Char of \'B\' " << (char) ch << std::endl; //correct
ch *= 2;
std::cout << "Int of \'B\' * 2 " << (int) ch << " Char of \'B\' * 2 " << (char) ch << std::endl; // error with int
ch = 'B' * 2;
std::cout << "Int of \'B\' * 2 " << (int) ch << " Char of \'B\' * 2 " << (char) ch << std::endl; // error with int
ch = 'B';
std::cout << "Int of \'B\' * 2 " << (int) ch * 2 << " Char of \'B\' * 2 " << char((int)ch * 2) << std::endl; /*correct but does not do what I want (edit the actual
character)*/
std::cout << "Int of \'B\' * 2 " << (int) 'B' * 2 << " Char of \'B\' * 2 " << char((int)'B' * 2) << std::endl; /*correct but does not do what I want (edit the actual
character)*/
ch = 'B' * 2;
ch /= 2;
std::cout << "Int of \'B\' *2 / 2' " << (int) ch << " Char of \'B\' * 2 / 2 " << (char) ch << std::endl; /*error with int because of the multiplication should be 66
and char should be \'B\'*/
ch = 'B';
ch /= 2;
std::cout << "Int of \'B\' / 2 " << (int) ch << " Char of \'B\' / 2 " << (char) ch << std::endl; //correct
ch *= 2;
std::cout << "Int of \'B\' / 2 * 2 " << (int) ch << " Char of \'B\' / 2 * 2 " << (char) ch << std::endl; //correct both multiplication and division work here
ch = 'B';
std::cout << "Int of \'B\' " << (int) ch << " Char of \'B\' " << (char) ch << std::endl; //correct
ch += 2;
std::cout << "Int of \'B\' + 2 " << (int) ch << " Char of \'B\' + 2 " << (char) ch << std::endl; //correct
ch -= 2;
std::cout << "Int of \'B\' + 2 - 2 " << (int) ch << " Char of \'B\' + 2 - 2 " << (char) ch << std::endl; //correct
ch = 'B';
ch -= 2;
std::cout << "Int of \'B\' - 2 " << (int) ch << " Char of \'B\' - 2 " << (char) ch << std::endl; //correct
ch += 2;
std::cout << "Int of \'B\' - 2 + 2 " << (int) ch << " Char of \'B\' - 2 + 2 " << (char) ch << std::endl; //correct
ch = 'B';
std::cout << "Int of \'B\' " << (int) ch << " Char of \'B\' " << (char) ch << std::endl; //corect
}
output is this:
Int of 'B' 66 Char of 'B' B
Int of 'B' * 2 -124 Char of 'B' * 2 ä
Int of 'B' * 2 -124 Char of 'B' * 2 ä
Int of 'B' * 2 132 Char of 'B' * 2 ä
Int of 'B' * 2 132 Char of 'B' * 2 ä
Int of 'B' *2 / 2' -62 Char of 'B' * 2 / 2 ┬
Int of 'B' / 2 33 Char of 'B' / 2 !
Int of 'B' / 2 * 2 66 Char of 'B' / 2 * 2 B
Int of 'B' 66 Char of 'B' B
Int of 'B' + 2 68 Char of 'B' + 2 D
Int of 'B' + 2 - 2 66 Char of 'B' + 2 - 2 B
Int of 'B' - 2 64 Char of 'B' - 2 @
Int of 'B' - 2 + 2 66 Char of 'B' - 2 + 2 B
Int of 'B' 66 Char of 'B' B
Press <RETURN> to close this window...
I guess I can try and make an object that will contain all of the unicode characters then use that instead of a character. I'll let you know how it goes.