C++ 动态申请数组的一个Demo 女爷i 2022-08-21 07:41 148阅读 0赞 void CDeleteDirTestDlg::OnBnClickedBtnTest() { //3,7,20,31 CString strBandDetails=_T(""); int iNum=4; int *pV=new int[iNum]; CString strBandDetails2=_T("3,7,20,31"); for (int i=0;i<iNum;i++) { CString strTemp=_T(""); int t=strBandDetails2.Find(','); if (-1 !=t) { int band0=atoi(strBandDetails2.Left(t)); if (band0<10) { strTemp.Format(_T("0%d"),band0); } else { strTemp.Format(_T("%d"),band0); } pV[i]=band0; strBandDetails=strBandDetails+strTemp; } else { int band1=atoi(strBandDetails2); if (band1<10) { strTemp.Format(_T("0%d"),band1); } else { strTemp.Format(_T("%d"),band1); } pV[i]=band1; strBandDetails=strBandDetails+strTemp; } strBandDetails2=strBandDetails2.Mid(t+1,strBandDetails2.GetLength()); } CString s=strBandDetails; } int *pV=new int[iNum]; 扩展一下 type \*pV=new type\[iNum\];
还没有评论,来说两句吧...