在VS2013编译器里,在debug或release模式下
//#include "stdlib.h"
//#include "math.h"
#include
#include
using namespace std;
#define PI 3.14159//圆周率宏定义
#define LENGTH_NAME_BMP 30//bmp图片文件名的最大长度
errno_t err;
void main()
{
char Filename[LENGTH_NAME_BMP];
cout << "请输入所需要读取的文件名" << endl;
cin >> Filename;
FILE *fpi=NULL, *fpw;
//cout << fpi << endl;
err = fopen_s(&fpi, Filename,"rb");
/*int i = err;
cout << i << endl;
cout << fpi << endl;*/
if (err == 0)
{
unsigned short filetype;
fread(&filetype, 1, sizeof(unsigned short), fpi);
if (filetype != 0x4d42)
{
cout << "文件不是BMP类型" << endl;
return ;
}
}
else
{
cout << "打开文件失败,错误代码:" << err << endl;
}
system("pause");
}
err = fopen_s(&fpi, Filename,"rb");
err的值都非0,也就是函数运行失败。
而在debug或release的文件里的 exe里运行 就能运行成功(err的值为0,fpi也不是空指针)