簡體   English   中英

從文件中讀取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的目的將任何對象解釋為字符數組。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM