vector<CString> Split(CString string)
{
CString oriStr=string;
vector<CString> strVec;
while (true)
{
CString n = oriStr.SpanExcluding(L",");//逗号分隔字符串
strVec.push_back(n);
oriStr = oriStr.Right(oriStr.GetLength()-n.GetLength()-1);
if (oriStr.IsEmpty())
{
break;
}
}
return strVec;
}
void CgenerateTxtDlg::OnBnClickedButton1()
{
//CString m_input,m_output对应视图层控件
std::vector<CString> list = Split(m_input);
if(list.size()!=4)
{
AfxMessageBox(L"输入参数不合法");
return;
}
swscanf_s(list[0].GetString(),L"%d",&row);
swscanf_s(list[1].GetString(),L"%d",&col);
swscanf_s(list[2].GetString(),L"%d",&width);
swscanf_s(list[3].GetString(),L"%d",&height);
TRACE("row,col,width,height=%d,%d,%d,%d\n",row,col,width,height);
int count =0;
CString csDst;
for (int i = 0; i < row; i++)
{
for(int j = 0; j <col; j++)
{
CString cs;
cs.Format(L"a%02d = %d %d %d %d\r\n",count,j*width,i*height,width,height);
csDst.Append(cs);
count++;
}
}
m_output = csDst;
UpdateData(FALSE);//数据上传到视图
}
CString的常见使用方式例子代码
最新推荐文章于 2022-01-07 22:45:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)