我在我的程序中有一個函數,輸出一個數據結構,它包含兩種格式,一個文本和一個二進制文件的三個雙打。調試和發佈模式給出不同的輸出
當我在調試和發佈模式下運行程序時,最終得到不同的二進制輸出,但輸出相同的文本。到底是怎麼回事?
下面是二進制輸出代碼:
void outputPoints(xyz* points, string description, int length, param parameters)
{
stringstream index;
index.str("");
index << setw(3) << setfill('0') << parameters.stage;
string outputName = parameters.baseFileName + " " + index.str() + " " + description + ".bin"; // create file name
ofstream output; // create output object
cout << "Output " << outputName.c_str() << "...";
output.open(outputName.c_str(), std::ios::binary | std::ios::out); // open or create file for output
output.write(reinterpret_cast<char*>(points), (sizeof(xyz) * length));
output.close(); // close output object
cout << "done" << endl;
}
那麼,是不是因爲某種與我的結構的字節對齊導致了這種情況呢?該結構只包含3個雙打,寫入功能幾乎只是將RAM中的數據從RAM轉儲到HD。 – Faken 2011-03-22 16:29:22