C++中EOF的问题
来源:百度知道 编辑:UC知道 时间:2024/06/22 17:13:44
为什么以下语句得到的值是-1:
cout<<"The character EOF has the value "<<EOF<<endl;
而以下语句得到的值是4542287?
cout<<"The character EOF has the value "<<static_cast<int>('EOF')<<endl;
大致理解了,是这样子吧?
E--45(H)--69(O)
O--4f(H)--79(O)
F--46(H)--70(O)
但是EOF是454f46(H)--4542287(O)吧?
cout<<"The character EOF has the value "<<EOF<<endl;
而以下语句得到的值是4542287?
cout<<"The character EOF has the value "<<static_cast<int>('EOF')<<endl;
大致理解了,是这样子吧?
E--45(H)--69(O)
O--4f(H)--79(O)
F--46(H)--70(O)
但是EOF是454f46(H)--4542287(O)吧?
EOF 只是一个标志
可能
#defin EOF (-1)
之类的东西
你以为那用括号括起来还能表达EOF的意思了吗?
是3个字符的组合
运行一下这个你就全明白了,不然我也没有办法了
#include <iostream.h>
void main()
{
cout <<EOF<<endl;
cout <<hex<<(int)'E'<<endl;
cout <<hex<<(int)'O'<<endl;
cout <<hex<<(int)'F'<<endl;
cout <<static_cast<int>('EOF')<<endl;
cout <<dec<<static_cast<int>('EOF')<<endl;
}