++ch和ch+1有什么不同?
#include <iostream>int main()
{
using namespace std;
char ch;
cout<<"Type, and I shall repeat.\n";
cin.get(ch);
while(ch != '.')
{
if(ch == '\n')
cout<<ch;
else
cout<<++ch; //为什么ch+1就不行?
cin.get(ch);
}
cout<<"\nPlease excuse the slight confusion.\n";
return 0;
} ++ch,用cout输出的还是字符,
而ch+1就变成了与之对应的ASCII值,
比如输入的是abc,用++ch得到的是bcd,而用ch+1得到的9899100 b的ASCII码是98,c是99,d是100
页:
[1]