我有一个问题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() 的结果相同。