Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
代码非常简单。
unsigned char a_byte; ifstream a_file("C:/file.bin", ios_base::binary); if (a_file.is_open() && a_file.good()) { a_file.seekg(0); a_file >> a_byte; a_file.close(); }
问题是它不会从单字节文件中读取 09h - 我只是在 a_byte var 中得到零。它确实适用于不同的值。什么原因?
流类operator>>在读入目标变量之前会跳过空格。这里char值09h是TAB,算作空格,跳过。
operator>>
09h
如果您想读取每个字符,请尝试该get功能。
get