c++ (VS2012) stdio:不能读取一个字节的文件,如果字节是09h
C++ (VS2012) stdio: Can't read one-byte file if that byte is 09h
代码很简单。
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中得到0 .它确实可以处理不同的值。原因是什么?
流类的operator>>
将在读入目标变量之前跳过空白。这里的字符值09h
是TAB,它被计算为空白并被跳过。
如果你想读取每一个字符,试试get
函数
相关文章:
- 在UNIX系统中使用DIR查找文件的字节大小
- 从文件中读取多个字节,并将它们存储在C++中进行比较
- 如何在文件中查找字节序列
- 读取文件中所有可能的十六进制 16 字节序列并打印每个序列
- 使用 stbi_write_png,如何将 0 和 1 的矩形字节数组转换为单色 png 文件?
- 如何使用 fprintf 将连续的 512 字节保存到文件中
- 用于 progmem 的C++和头文件压缩的 Web 文件字节数组
- 为什么未关闭的文件大小为 4 字节
- 我能确定从文件中读取的 32 字节二进制数据等于 256 位吗?
- Ascii .txt文件到字节数组 - C++
- 多部分/表单数据丢失大文件的字节
- 我该如何循环遍历我的数组(缓冲区——包含一个文本文件),并将其打印成30字节的块
- 程序错误地读取了二进制文件的一个字节
- 如何从 C 或 C++ 格式的文件中删除字节?
- C++ - 将任何文件的字节读取到无符号字符数组中
- ofstream将额外的零字节写入Unix服务器上的文件
- 传输文件一次又一次地发送相同的字节
- 编码大于原始文本:如何获取零和一的字符串并将它们作为实际字节写入文件
- 查找二进制文件中字节序列的所有匹配项
- C++ 使用单个输入字节文件的不同部分实例化堆栈上的成员类