morechar.cpp 800 B

12345678910111213141516171819202122232425
  1. // morechar.cpp -- the char type and int type contrasted
  2. #include <iostream>
  3. int main()
  4. {
  5. using namespace std;
  6. char ch = 'M'; // assign ASCII code for M to ch
  7. int i = ch; // store same code in an int
  8. cout << "The ASCII code for " << ch << " is " << i << endl;
  9. cout << "Add one to the character code:" << endl;
  10. ch = ch + 1; // change character code in ch
  11. i = ch; // save new character code in i
  12. cout << "The ASCII code for " << ch << " is " << i << endl;
  13. // using the cout.put() member function to display a char
  14. cout << "Displaying char ch using cout.put(ch): ";
  15. cout.put(ch);
  16. // using cout.put() to display a char constant
  17. cout.put('!');
  18. cout << endl << "Done" << endl;
  19. // cin.get();
  20. return 0;
  21. }