// morechar.cpp -- the char type and int contrasted
#include <iostream>
int main()
{
using namespace std;
char ch = 'M';
int i = ch;
cout << "The ASCII code for " << ch << " is " << i << endl;
cout << "Add one to the character code: " << endl;
ch = ch + 1;
i = ch;
cout << "The ASCII code for " << ch << " is " << i << endl;
// using the cout.put() member function to display a char
cout << "Displaying char ch using cout.put(): ";
cout.put(ch);
cout.put('!');
cout << endl << "Done" << endl;
return 0;
}
输出:
The ASCII code for M is 77
Add one to the character code:
The ASCII code for N is 78
Displaying char ch using cout.put(): N!
Done