65,187
社区成员




#include "iostream"
#include "afxwin.h"
using namespace std;
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
int main()
{
int Rows=10;
int Cols=5;
int i=0,j=0;
CString **ArrayData;
CString Value;
//创建指针数组
ArrayData=new CString*[Rows];
for (i=0;i<Rows;i++)
{
//为每一行分配内存空间
ArrayData[i]=new CString[Cols];
}
//设置数组的值
for (i=0;i<Rows;i++)
{
for (j=0;j<Cols;j++)
{
Value.Format("i:%d,j:%d",i,j);
ArrayData[i][j]=Value;
}
}
//显示数组的值
for (i=0;i<Rows;i++)
{
for (j=0;j<Cols;j++)
{
Value.Format("%s",ArrayData[i][j]);
cout<<(LPCTSTR)Value<<"\t\t";
}
cout<<endl;
}
//释放内存
for (i=0;i<Rows;i++)
{
delete[] ArrayData[i];
ArrayData[i]=NULL;
}
delete[] ArrayData;
ArrayData=NULL;
_CrtDumpMemoryLeaks();
return 0;
}
int main()
{
{
//...
} _CrtDumpMemoryLeaks();
return 0;
}