我在与cin.get()
问题已经设置字符的ASCII码不同:cin.get()ASCII码是比代码
虽然得到一个字符,我将其转换为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,它必须与ord()在PHP中的结果相同。
我猜测229字符是在控制台窗口中使用OEM代码页852。 – 2012-07-26 19:37:38
@MichaelBurr,我只是想到了自己。它花了很多试验和错误。它是有道理的,这将被一个控制台窗口使用。 – 2012-07-26 19:40:38
我试过这个脚本来得到我的应用使用的字符集: cout << setlocale(LC_ALL,“”)<< endl; 结果是:斯洛伐克斯洛伐克.1250,所以Windows 1250,当我看那张Win1250代码表时,有一个是242,但我的结果仍然是229 - cp852 – jakubinf 2012-07-27 12:14:50