您的位置:首页 > 编程语言 > C语言/C++

C++输入流位置的小变动对程序的影响

2015-09-26 17:05 531 查看
#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 赋值所致
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ c++基础