0
現在我有一個C++程序,在兩列數據從文本文件使用類似二進制數據
while(!file.eof())
{
double a, b;
file >> a >> b; // extracts 2 floating point values separated by whitespace
// do something with them
}
現在我想調整這個代碼的兩列讀取讀取列讀來自.bin文件的二進制數據。我仍然希望在我的程序的其餘部分將這些值視爲雙打。什麼是最簡單的方法來完成這一點?
編輯:
我寫這樣的二進制數據的Python程序。我認爲它分爲兩列。
import struct
c = struct.Struct('=ff')
with open('numbers.bin', 'w+') as outf:
for r, k in nonzero:
outf.write(c.pack(r, k))
http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong – chris 2013-03-22 00:52:50
你是什麼意思的二進制兩列數據?兩項? 'fread' 4個字節兩次 – 2013-03-22 01:07:09