下面一段代码:
 GetSystemTime(&st1);    strDate.Format("%4d-%2d-%2d",st1.wYear,st1.wMonth,st1.wDay); strTime.Format("%2d:%2d:%2d:%3d",st1.wHour,st1.wMinute,st1.wSecond,st1.wMilliseconds);    strName=strDate+strTime+".jpg";
//  if(iter == params.end()) params["-out"] = "AV_Image1.jpg";
    if(iter == params.end()) params["-out"] = strName;    ……   std::ofstream fout(params["-out"].c_str(), std::ios_base::binary);
if(!fout)
    MessageBox("could not be opened");
else

for(i = 0; i < iBufferSize; i++)
fout << pcImageBuffer[i];
if(!fout != true)
{
                MessageBox("\image saved to file: ");
fout.close();
}
}
这段程序,
如果用现在被注释的那条代码,就可以顺利的输出结果,但是如果用没有注释的那一条,就会弹出MessageBox("could not be opened");请问是为什么呢?

解决方案 »

  1.   

    说明没有这个文件啊.
    你的格式化可能有问题,应该是
     strDate.Format("%04d-%02d-%02d",st1.wYear,st1.wMonth,st1.wDay);strTime.Format("%02d:%02d:%02d:%03d",st1.wHour,st1.wMinute,st1.wSecond,st1.wMilliseconds);
      

  2.   

    路径问题啊,楼主用相对路径,那么图片一定要放在当前项目下面的。
    strName=strDate+strTime+".jpg";断点查找字符串拼接是否正确
    PS:楼主用AV_IMAGE啊,显示黄色图片可是不对的呀!
      

  3.   

    我的问题就是,字符串那么拼接不可以么?
    为什么我如果弹出一个MessageBox,先试一下strName,检查一下是没有问题的,
    但是就是无法生成合法的文件名呢?顺便AV是arecont vision的缩写,是一家摄像头公司……
      

  4.   

    你在strDate.Format("%4d-%2d-%2d",st1.wYear,st1.wMonth,st1.wDay);strTime.Format("%2d:%2d:%2d:%3d",st1.wHour,st1.wMinute,st1.wSecond,st1.wMilliseconds);  strName=strDate+strTime+".jpg";的后面用AfxMessageBox(strName)显示看看strName中的文件路径有没有问题。
      

  5.   

    是啊,你MessageBox输出strName的值看看对不对?
      

  6.   

    最好能DEBUG 单步跟踪试一下。
      

  7.   

    windows就是不让文件名带冒号,看你怎么办
      

  8.   

    那如果是需要把文件放在一个目录下呢?
    像是这样str="D:\\"这样的也不行么?