vc程序debug不知道为什么? help me
aoxue 2004-04-19 09:07:58 有一段代码每次运行都有错误提示,是错在那啊?我估计是new .delete出错了,是不是
要测试new,delete?
但不知道怎么改啊?for example:
#include<iostream>
#include<cstring>
using namespace std;
int main(void) {
const char *pc0 = "this is very long string";
char *pc1 = new char[100];
int lenth = strlen(pc0);
for(int ix = 0; ix < lenth; ix++) {
pc1[ix] = pc0[ix];
pc0++;
pc1++;
cout << "*pc0 = " << *pc0 << endl;
}
cout << "*pc1 = " << *pc1 << endl;
delete [] pc1;
return 0;
}
===============================================================
编译能通过,可运行就出问题了,编译器提示:
Debug Asserting Failed!
Program:c:/Program Files/microsoft Visual Studio/MyProject/stringVersion
/DEBUG/stringVersion.exe (这是我vc的安装路径)
File:dbgheap.c
line:100012
expression:CtrIsValidHeapPointer(pUserData)
For information on how yout program can cause an assertion failure
cee the visual c++ document on asserts .
(press retry debug the application)