[英]Read uint32_t values from file
I'd like to read uint32_t integers from a file using the code below. 我想使用以下代码从文件中读取uint32_t整数。 ifstream only accepts a pointer to a char array. ifstream只接受一个指向char数组的指针。 Is there another way to read uint32_t values using a code similar to the below? 还有另一种使用类似于以下代码的方式读取uint32_t值的方法吗?
int readCount;
uint32_t buffer[SIZE];
while ( fin.read( &buffer[0], SIZE)
|| (readCount = fin.gcount()) != 0 ) {
// some code
}
Use a cast, eg: 使用演员表,例如:
if (fin.read(reinterpret_cast<char *>(buffer), sizeof buffer) &&
fin.gcount() == sizeof buffer)
{
// use buf
}
(Interpreting any object as an array of characters is expressly allowed, precisely for the purpose of I/O.) (明确地允许出于I / O的目的将任何对象解释为字符数组。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.