我想把一组变量定义成这样,放在循环里。
j=1;
while(j!=5)
{
int a(j); //这里(j)表示一个数字,从零开始。
...;
j++;
}
这个做的目的是想:j=1,int a1,然后j=2,int a2,j=3,int a3,j=4,int a4,请问在循环里如何实现我这样的定义方式。
j=1;
while(j!=5)
{
int a(j); //这里(j)表示一个数字,从零开始。
...;
j++;
}
这个做的目的是想:j=1,int a1,然后j=2,int a2,j=3,int a3,j=4,int a4,请问在循环里如何实现我这样的定义方式。
j=1;
while(j!=5)
{
CTreeCtrl pt(j); //这里(j)表示一个数字,从零开始。
...;
j++;
}
该如何处理?
tvinsert.hParent = NULL;
tvinsert.hInsertAfter = TVI_LAST;
tvinsert.item.mask = TVIF_TEXT;
tvinsert.item.hItem = NULL;
tvinsert.item.state = 0;
tvinsert.item.stateMask = 0;
tvinsert.item.cchTextMax = 6;
tvinsert.item.iSelectedImage = 0;
tvinsert.item.cChildren = 0;
tvinsert.item.lParam = 0;
tvinsert.item.pszText = strGrade[2]; //根结点
HTREEITEM hGrade1 = ptc->InsertItem(&tvinsert);
tvinsert.hParent = hGrade1;
tvinsert.item.pszText = strType[0]; //根结点下第一层(1)
HTREEITEM hLevel3 = ptc->InsertItem(&tvinsert);
tvinsert.hParent = hLevel3;
for(int mm3 = 0;mm3 < m;mm3++)
{
tvinsert.item.pszText = strLevel[mm3];//根结点下第二层
ptc->InsertItem(&tvinsert);
}
tvinsert.hParent = hGrade1;
tvinsert.item.pszText = strType[1]; //根结点下第一层(2)
HTREEITEM hLevel4 = ptc->InsertItem(&tvinsert);
tvinsert.hParent = hLevel4;
for(int mm2 = 0;mm2 < m;mm2++)
{
tvinsert.item.pszText = strLevel[mm2];
ptc->InsertItem(&tvinsert);
}
tvinsert.hParent = hGrade1;
tvinsert.item.pszText = strType[2]; //根结点下第一层(3)
HTREEITEM hLevel5 = ptc->InsertItem(&tvinsert);
tvinsert.hParent = hLevel5;
for(int mm1 = 0;mm1 < m;mm1++)
{
tvinsert.item.pszText = strLevel[mm1];
ptc->InsertItem(&tvinsert);
}
strGrade[2];这个都是从数据库里读取出来的。
while(j!=5)
{
int a(j); //这里(j)表示一个数字,从零开始。
...;
j++;
}
中a1,a2...的生存期只在while{}中,这样的定义是所愿的吗?改为static int a(j);可以解决这个问题。。
用宏 看这个版本:
#define j 1
#define _CREATEINTARR(MAX)\
while(j!=MAX)\
{\
static int a##j;\
j=j+1;\
}
while(j!=5)
{
int a(j); //这里(j)表示一个数字,从零开始。
...;
j++;
}
我是想达到这样的目的:while(j!=5)
{
int a(j);
...
j++;
}
把循环分解一下,就变成:
第一次循环:
j=1;
int a1;
j++;
第二次循环
j=2;
int a2;
j++;
第三次循环
j=3;
int a3;
j++;
....是这样的目的。那控件如果也这样,可以吗?
int j=1
CMyCtrl myCtrl[4];
whle(j!=5)
{
myCtrl[j-1].value = j;
j++;
}
for(int i=0;i<4;i++)
TRACE("%d",myCtrl[i].value);