为什么编译通过,写入也正常,在运行的时候会提示DEBUG,百思不得其解
#include<iostream.h>
#include<stdio.h>
#include<windows.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef unsigned char byte;
unsigned char *p;
vector<unsigned char>v(0);
bool rDrwSize()
{
byte DrwSize=0;
FILE *fp=fopen("a264.bmp","rb");
if(fp==0) return 0;
p=new unsigned char[4];
fseek(fp,88,0);
fread(&(v[0]),2,1,fp);//试验数据写入向量指向的空间中,不写给指针p指向的空间中
cout<<int(v[0])<<endl;
p=&v[0];
cout<<int(p[0])<<endl;
cout<<&p<<endl;
FILE *fp1=fopen("a222.img","wb");
if(fp1==0) return 0;
fwrite(p,1,2,fp1);
fclose(fp);
fclose(fp1);
return 1;
}
int main()
{
rDrwSize();
return 0;
}
编译正常,后来写的文件的两字节的值也正确,但内存有问题,程序运行后会跳出debug error:
Debug Error!
program: D:\A\13\Debug\a1.exe
DAMAGE:after Normal block(#50) at 0x00441b10
(press Retry to debug the application)
终止(A) 重试(R) 忽略(I)