![](/img/trans.png)
[英]How to write data into a buffer and write the buffer into a binary file with a second thread?
[英]write a float buffer to a binary file
我嘗試這樣做,getHeight()返回數據的Height和getWidth()的寬度。
ofstream output(filename, ios::out | ios::binary);
output.write((char *)buffer, img.getHeight() * img.getWidth() * 3);
我也嘗試這個,因為i = 0到i = 3 * height * width
fp = fopen(filename, "wb");
fwrite(reinterpret_cast<char*>(&buffer[i][0]), 1, 3*height*width, fp);
浮點數每個為4個字節。 fwrite()不知道您要編寫的類型,因此對於大小,還需要乘以每個元素的大小。
fwrite(reinterpret_cast<char*>(&buffer[i][0]), 1, 3*height*width * sizeof(float), fp);
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main() {
ofstream out("blah.txt");
float val = 10.0f;
out << fixed << setprecision(5) << val << endl;
out.close();
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.