【发布时间】:2012-07-26 19:14:33
【问题描述】:
cin.get() 有问题:
在获取 char 时,我将其转换为 int,但是当我通过控制台输入时,结果与已在代码中设置时不同。
示例如下:
int ord(unsigned char chr){
int ret=int(chr);
return ret;
}
int main(){
unsigned char chr='ň'; //This is my constant character 'ň' for now
cout<<ord(chr)<<endl; //outputs : 242 ,which is alright for me, because it is same as in PHP and that I need
chr=cin.get(); //now I change my constant character 'ň' to 'ň' written through console
cout<<ord(chr)<<endl; //outpus : 229 ,which is wrong for me, because its not same as in PHP
}
我该如何解决这个问题?
我要的是 242,不是 229,它必须和 PHP 中 ord() 的结果一样。
【问题讨论】:
标签: c++