[MFC] CString 형 2차원 배열 동적할당
생성 - char와 CString형
char **strLine = new char*[nLine]; //[라인수][최대라인글자수]
for(int strnArray = 0; strnArray < nLine; strnArray++)
{
strLine[strnArray] = new char [MAX_LINE_CHAR]; //MAX_LINE_CHAR (200)
}
========================================================================================
#define nLine 100
#define ITEM_ALARM 15
CString **strData = new CString*[nLine]; //AddRecord에서 사용할 문자열 [라인수][아이템수]
for(int nArray = 0; nArray < nLine; nArray++)
{
strData[nArray] = new CString [ITEM_ALARM]; //MAX ITEM - ALARM (11)
}
Func( strData ); // 함수인자로 넘기기 => Header 선언부 : Func(CString **strData);
해제
for(int cntDel = 0; cntDel < nLine; cntDel++)
{
delete [] strLine[cntDel]; // char 형
delete [] strData[cntDel]; // String 형
}
delete [] strLine; // char 형
delete [] strData; // String 형
[출처] 2차원 배열의 동적할당|작성자 하드코딩