std::operator>>默认跳过回车,要显式指定格式
unsigned char temp;
std::ifstream file("myfile.bin", std::ios::in | std::ios::binary);
file >> std::noskipws >> temp;
追根溯源:
std::istream::operator>>
std::operator>> (istream)
std::istream::sentry
std::skipws
isspace
operator>>操作底层会先构造一个std::istream::sentry对象,sentry对象默认noskipws标志设为false,white-space character会被跳过
除了回车,以下字符均是默认跳过