调试和发布模式给出不同的输出

问题描述:

我在我的程序中有一个函数,输出一个数据结构,它包含两种格式,一个文本和一个二进制文件的三个双打。调试和发布模式给出不同的输出

当我在调试和发布模式下运行程序时,最终得到不同的二进制输出,但输出相同的文本。到底是怎么回事?

下面是二进制输出代码:

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

调试版通常初始化与一些模式的变量。通常分配的数据具有内容CDCD,被FEEE覆盖删除的对象。初始化变量时,CDCD模式被覆盖。发布版本不会启动这些模式。

值得检查你的程序是否有未初始化的变量。你可以定义一个转储函数,只打印可疑变量的(第一个字节)。

+0

那么,是不是因为某种与我的结构的字节对齐导致了这种情况呢?该结构只包含3个双打,写入功能几乎只是将RAM中的数据从RAM转储到HD。 – Faken 2011-03-22 16:29:22

我不知道你是否有解决你的问题,我没有看你的代码。 我有同样的问题,因为我将unsigned char和unsigned short添加到unsigned short中。我将所有变量改为unsigned short,问题解决了。