我的CString 转化到int的实现,请问有简便方法吗?
void CMyDialog::OnBnClickedButton1()
{ CString s;
CEdit* edit1=(CEdit*)GetDlgItem(IDC_EDIT1);
edit1->GetWindowTextA(s);
int loop;
int len=s.GetLength();
char c;
int *i1=new int [len];
for(loop=0;loop<len;loop++)
{
c=s.GetAt(loop);
i1[loop]=atoi(&c);
}
int cym=0;
for(loop=0;loop<len;loop++)
{
cym=cym*10;
cym=cym+i1[loop];
} s.Format(_T("%d"),cym);
CEdit* edit2=(CEdit*)GetDlgItem(IDC_EDIT2);
edit2->SetWindowTextA(s);
delete []i1;
}
void CMyDialog::OnBnClickedButton1()
{ CString s;
CEdit* edit1=(CEdit*)GetDlgItem(IDC_EDIT1);
edit1->GetWindowTextA(s);
int loop;
int len=s.GetLength();
char c;
int *i1=new int [len];
for(loop=0;loop<len;loop++)
{
c=s.GetAt(loop);
i1[loop]=atoi(&c);
}
int cym=0;
for(loop=0;loop<len;loop++)
{
cym=cym*10;
cym=cym+i1[loop];
} s.Format(_T("%d"),cym);
CEdit* edit2=(CEdit*)GetDlgItem(IDC_EDIT2);
edit2->SetWindowTextA(s);
delete []i1;
}
解决方案 »
- 求问MFC中int Send(const void* lpBuf, int nBufLen, int nFlags = 0)问题----连续发送,合并接收
- SQL server连接 GetadoEOF()问题
- 【求助】获取表里所有字段的值,感谢!
- 急,关于VFW中capDlgVideoSource的问题
- 打成安装包后,怎么样实现active文件自注册?
- 如何 改变 对话框 默认的 菜单栏和工具栏的背景色?
- 如何讲数组 char t[]={0x01,0x02......0xff} 输出为string 0102...ff ?
- 为什么取不到输入的字符
- 请教关于树的ITEM选择改变时的问题
- AnimateWindow函数怎么不能用
- vc++如何判断一个WEB服务是否启动?急!!!!!!!!!!!!!!!
- OpenGL纹理对象到是什么??
int a = atoi(s);
GetDlgItem(IDC_EDIT1)->GetWindowText(s);
int b=atoi(s.GetBuffer(s.GetLength());
int b=atoi(a);//这里b=123了
可以对CString 直接转换
int n = atoi(str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
要记得ReleaseBuffer哦!