2011-03-22 85 views
0

我在我的程序中有一個函數,輸出一個數據結構,它包含兩種格式,一個文本和一個二進制文件的三個雙打。調試和發佈模式給出不同的輸出

當我在調試和發佈模式下運行程序時,最終得到不同的二進制輸出,但輸出相同的文本。到底是怎麼回事?

下面是二進制輸出代碼:

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; 
} 

回答

1

調試版通常初始化與一些模式的變量。通常分配的數據具有內容CDCD,被FEEE覆蓋刪除的對象。初始化變量時,CDCD模式被覆蓋。發佈版本不會啓動這些模式。

值得檢查你的程序是否有未初始化的變量。你可以定義一個轉儲函數,只打印可疑變量的(第一個字節)。

+0

那麼,是不是因爲某種與我的結構的字節對齊導致了這種情況呢?該結構只包含3個雙打,寫入功能幾乎只是將RAM中的數據從RAM轉儲到HD。 – Faken 2011-03-22 16:29:22

0

我不知道你是否有解決你的問題,我沒有看你的代碼。 我有同樣的問題,因爲我將unsigned char和unsigned short添加到unsigned short中。我將所有變量改爲unsigned short,問題解決了。

相關問題