64,648
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include <iostream>
#include <crtdbg.h>
#include <malloc.h>
#include <string>
using namespace std;
class myString
{
public:
myString();
~myString();
private:
int nCount;
char *pszbuffer;
};
myString::myString()
{
this->nCount = 0;
this->pszbuffer = NULL;
cout<<"This is conStruction Function..."<<endl;
}
myString::~myString()
{
cout<<"This is Destory Function...."<<endl;
}
int main(void)
{
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag( tmpFlag );
myString my;
char *newString = (char*)malloc(sizeof(char) * 100);
strcpy(newString,"I come from china...");
cout<<newString<<endl;
//free(newString);
return 0;
}
//上面的代码,当你调试,退出的时候,输出窗口显示:
/*
Detected memory leaks!
Dumping objects ->
{121} normal block at 0x003A60C0, 100 bytes long.
Data: <I come from chin> 49 20 63 6F 6D 65 20 66 72 6F 6D 20 63 68 69 6E
Object dump complete.
*/