#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;
cout << "Displaying char ch using cout.put(ch):";
cout.put(ch);
cout.put('!');
cout << endl << "Done" << endl;
return 0;
}
其实char在内存中是以二进制的整型存储的,其数值对应ASCII码,可以用整型输出
put()函数输出的是一个字符,与cout << "s";不同的是,前者输出字符,后者输出的是字符串