|
-
July 14th, 2004, 06:05 AM
#1
Setting size of Multi-dimensional Array dynamically
good day to all! i would like to use a multi-dimensional array which size and range are setup dynamically. the array will be placed in the public location of my class because this array will be the one to catch data from another class (having a multi-dimensional array too)..
i try CStringArray but i cant set the additional range for it
Normal Use:
CStringArray cArrRowCol[5];
i want was:
CStringArray cArrRowCol[i]; which " i " varies from what will i give to its value
any idea of it? thanks
-
July 14th, 2004, 06:17 AM
#2
This FAQ might help...
-
July 14th, 2004, 06:48 AM
#3
Hi
try this
typedef CStringArray* PSTRARRAY;
PSTRARRAY *cArrRowCol;
int x = 5;
cArrRowCol = new PSTRARRAY[x];
for(int i=0;i<5;i++)
{
for(int j=0;j<3;j++)
{
CString str;
str.Format("%d %d",i,j);
cArrRowCol[i]->Add(str);
}
}
hope this could solve your problem
VladimirV
-
July 15th, 2004, 12:22 AM
#4
To VladimirV:
i already try your approach the multi-dimensional array unable to catch the data that i have thrown. here is my code snipet:
//header file
typedef CStringArray *PSTRARRAY;
class CReportUI : public CDialog
{
// Construction
public:
PSTRARRAY *cArrRowCol;
CManagerialReport cManage;
CStringArray mv_sArrType;
CString m_sDialogTitle;
CReportUI(CWnd* pParent = NULL); // standard constructor
}
//ccp file
BOOL CReportUI::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowText(m_sDialogTitle);
SetTypeSelection();
cArrRowCol = new PSTRARRAY[5];
cArrRowCol[0]->Add("hello"); // unable to catch the value
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
To Gabriel Fleseriu: How can i adopt the STL code to my MFC project? i dont have any idea of it...
-
July 15th, 2004, 12:37 AM
#5
sorry, there was a mistake, this is working well
typedef CStringArray* PSTRARRAY;
void CCg1Dlg::OnButton1()
{
PSTRARRAY cArrRowCol;
int x = 5;
cArrRowCol = new CStringArray[x];
for(int i=0;i<5;i++)
{
for(int j=0;j<3;j++)
{
CString str;
str.Format("%d %d",i,j);
cArrRowCol[i].Add(str);
}
}
TRACE("%s",cArrRowCol[0].GetAt(0));
TRACE("%s",cArrRowCol[1].GetAt(0));
TRACE("%s",cArrRowCol[2].GetAt(0));
}
VladimirV
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|