I'd like to read uint32_t integers from a file using the code below. ifstream only accepts a pointer to a char array. Is there another way to read uint32_t values using a code similar to the below?
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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.