注册 登录
编程论坛 VC++/MFC

为什么编译通过,写入也正常,在运行的时候会提示DEBUG,百思不得其解

lanriver 发布于 2012-07-10 00:06, 701 次点击

#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)
4 回复
#2
lanriver2012-07-10 00:08
求答案,最好给个解决的实例,谢谢各位高手了,小弟确实已经思考不通,才来请教大家。
#3
hellovfp2012-07-10 13:45
vector<unsigned char> v(3, 0);
#4
lanriver2012-07-10 20:21
谢谢版主的回答,我先试验,如果通行,版主肯赏绝面小弟对要请你喝花酒。
#5
lanriver2012-07-10 20:23
太感谢版主的大力支持,能够有你千分之一点的功能就好了,花酒我请了,成功运行.
1