mfc中CString转换为整数和char数组问题 牛人请进(100分奉上)

[复制链接]
查看11 | 回复5 | 2009-5-22 01:48:32 | 显示全部楼层 |阅读模式
CString str = "123";// 转换为char指针 char *p = str.GetBuffer(str.GetLength());// 转换为int变量 int i = atoi(p); cout << i << endl;// 转换为float变量 str = "123.32"; float f = atof(str.GetBuffer(str.GetLength())); cout << f << endl;...
回复

使用道具 举报

千问 | 2009-5-22 01:48:32 | 显示全部楼层
1还有CString转换为char数组char* buffer;buffer=new char[strData.GetLength()];WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,strData.GetBuffer(0),(int)strData.GetLength(),buffer,(...
回复

使用道具 举报

千问 | 2009-5-22 01:48:32 | 显示全部楼层
CString转为int型方法是先把CString转为char* (char数组),再转为intCString str="1";char *buf;buf=(LPCTSTR)str;int result=atoi(buf);...
回复

使用道具 举报

千问 | 2009-5-22 01:48:32 | 显示全部楼层
CString转成char 数组就强制类型转换就可以char 数组转成int 用库函数_atoi 或者这类的别的什么...
回复

使用道具 举报

千问 | 2009-5-22 01:48:32 | 显示全部楼层
比如CString str;str.format("%d",str);//格式化...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行