#include<iostream>
using namespace std;
int main()
{
char cl;
int i = cl;
cin >> cl;
cout << "The ASCII code for " << cl << " is ";
cout << i << endl;
cout << "Add one to the charecter code:" << endl;
cl = cl + 1;
i = cl;
cout << "The ASCII code for " << cl << " is ";
cout << i << endl;
cout << "Displaying char c using count.put(cl): ";
cout.put(cl);
cout << "!" << endl << "Done";
return 0;
}
注意将 int i = cl; 和 cin >> cl; 对调,如下
#include<iostream>
using namespace std;
int main()
{
char cl;
cin >> cl;
int i = cl;
cout << "The ASCII code for " << cl << " is ";
cout << i << endl;
cout << "Add one to the charecter code:" << endl;
cl = cl + 1;
i = cl;
cout << "The ASCII code for " << cl << " is ";
cout << i << endl;
cout << "Displaying char c using count.put(cl): ";
cout.put(cl);
cout << "!" << endl << "Done";
return 0;
}
分析后觉得是 i 放在前面,int 定义的 i 没被输入流输入的 cl 赋值所致