从文件中读取uint32_t值
Read uint32_t values from file
我想使用下面的代码从文件中读取uint32_t整数。Ifstream只接受指向char数组的指针。是否有另一种方法来读取uint32_t值使用类似于下面的代码?
int readCount;
uint32_t buffer[SIZE];
while ( fin.read( &buffer[0], SIZE)
|| (readCount = fin.gcount()) != 0 ) {
// some code
}
使用强制转换,例如:
if (fin.read(reinterpret_cast<char *>(buffer), sizeof buffer) &&
fin.gcount() == sizeof buffer)
{
// use buf
}
(明确允许将任何对象解释为字符数组,正是为了I/o的目的)
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法找到/读取配置文件.conf-FileIOException
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++将文本文件中的数据读取到结构数组中
- 正在将csv文件读取为双精度矢量
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 为什么在读取文件大小时文件IO速度会发生变化
- 正在读取二进制文件(is_open)
- 如何在c++中从文本文件中逐行读取整数
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 独立读取-修改-写入顺序
- 从文本文件中读取时钟时间和事件时间并进行处理
- 为什么当我使用双精度时,Qt<->Matlab 正确写入和读取我的字节,但存储 uint32 的字节不正确?
- 读取结构 -- uint32 不命名类型
- 从任何内存地址读取UInt32的最有效方法