69,382
社区成员
发帖
与我相关
我的任务
分享
ch=-1;
if(ch==-1)
[/quote]
1. 什么意思? 你说 getchar 返回的值不会是负数? 你输入中文看看.
2. 更不知道你想说什么了.[/quote]
1、中文就不应该用getchar, 要用fgetwchar,对应的结束符WEOF
单字节字符高位会被截,但好像没规律(alt-145 之类的双字节输入不算)。
2、只是回答你的(char)-1 与 (int)-1的问题了,别把他们转成二进制比较EOF
End-of-File
It is a macro definition of type int that expands into a negative integral constant expression (generally, -1).
It is used as the value returned by several functions in header <cstdio> to indicate that the End-of-File has been reached or to signal some other failure conditions.
It is also used as the value to represent an invalid character.
In C++, this macro corresponds to the value of char_traits<char>::eof().
ch=-1;
if(ch==-1)
[/quote]
1. 什么意思? 你说 getchar 返回的值不会是负数? 你输入中文看看.
2. 更不知道你想说什么了.ch=-1;
if(ch==-1)