gpt4 book ai didi

C++ (VS2012) 标准输入输出 : Can't read one-byte file if that byte is 09h

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:15 24 4
gpt4 key购买 nike

代码非常简单。

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,算作空格跳过。

如果您想读取每个字符,请尝试使用 get 函数。

关于C++ (VS2012) 标准输入输出 : Can't read one-byte file if that byte is 09h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14416073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com