程序在visual studio中运行,但发布可执行文件崩溃

时间:2012-09-16 15:52:43

标签: c++ visual-studio file exe file-handling

我已将其跟踪到我写入txt文件的时间。我已经检查过它是否已打开,并且在崩溃之前它会在文件中写入一行。

VS2012外部调试器将此Unhandled exception at 0x77112D24 (ntdll.dll) in DTC.exe: 0xC0000005: Access violation writing location 0x10000000抛给我,并指向fstream标题内的此函数virtual __CLR_OR_THIS_CALL ~basic_filebuf()

void main()
{
    vector<string> fileNames;
    vector<time_t> fileTimes;

    CImg<unsigned char> image("Image.bmp");

    ofstream out("Result_Data.txt",ios::out|ios::app);
    if(!out.is_open())
    {
        cout<<"File Not Opened!\n";
    }
    unsigned long originalSize = my_image_functions::getFileSize("Image.bmp");
    time_t before = 0, after = 0;

    before=clock();
    my_image_functions::compressDualLevelBTC(image,"dualBTC_2_8.dtc",2,8);
    after = clock();

    fileTimes.push_back(after-before);
    fileNames.push_back("dualBTC_2_8.dtc");

    //...
    /* Several of these segments*/
    //...


    before=clock();
    my_image_functions::compressDualLevelBTC(image,"dualBTC_32_64.dtc",32,64);
    after = clock();

    fileTimes.push_back(after-before);
    fileNames.push_back("dualBTC_32_64.dtc");

    while(!fileNames.empty() && !fileTimes.empty())
    {
        out<< fileNames.back() <<";"<< fileTimes.back() <<";"<< my_image_functions::getFileSize(fileNames.back()) << ";" << ((float) originalSize)/my_image_functions::getFileSize(fileNames.back()) << endl;
        fileNames.pop_back();
        fileTimes.pop_back();
        if(!out.is_open())
        {
            cout<<"File Not Opened!\n";
        }
    }
    out.close();
}

2 个答案:

答案 0 :(得分:1)

最可能的原因是您在运行发布版本时缺少必需的dll。

在可执行文件上运行Dependency Walker:http://dependencywalker.com/

答案 1 :(得分:0)

您好像检查文件是否打开。如果不是,则打印消息“未打开”但仍然继续?

ofstream out("Result_Data.txt",ios::out|ios::app);
if(!out.is_open())
{
    cout<<"File Not Opened!\n";
}