如何把CString型转为int型的?谢谢

jerrybao 2003-04-21 04:58:40
如何把CString型转为int型的?谢谢
...全文
145 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
u2m 2003-04-24
  • 打赏
  • 举报
回复
atoi
sailor_2002 2003-04-24
  • 打赏
  • 举报
回复
atoi函数
丁淇石头 2003-04-21
  • 打赏
  • 举报
回复
直接用atoi或atol就行。转化为float型的用atof.
laolaoliu2002 2003-04-21
  • 打赏
  • 举报
回复
以上是把int 转换为string
以下是把string 转换为数值
/* ATOF.C: This program shows how numbers stored
* as strings can be converted to numeric values
* using the atof, atoi, and atol functions.
*/

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
char *s; double x; int i; long l;

s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );

s = "7.8912654773d210"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s, x );

s = " -9885 pigs"; /* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );

s = "98854 dollars"; /* Test of atol */
l = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}

Output
atof test: ASCII string: -2309.12E-15 float: -2.309120e-012
atof test: ASCII string: 7.8912654773d210 float: 7.891265e+210
atoi test: ASCII string: -9885 pigs integer: -9885
atol test: ASCII string: 98854 dollars long: 98854

laolaoliu2002 2003-04-21
  • 打赏
  • 举报
回复
int j = 2345;
char number[5];
_itoa(j,number,10);
CString temp;
temp = number;
birdzxy 2003-04-21
  • 打赏
  • 举报
回复
实验了一下,直接用atoi(CString)也可以
birdzxy 2003-04-21
  • 打赏
  • 举报
回复
CString s("1234");
int i;
char temp[10];

strcpy(temp, (LPCTSTR)s);
i = atoi(temp);
cdwy411 2003-04-21
  • 打赏
  • 举报
回复
函数atol()!
birdzxy 2003-04-21
  • 打赏
  • 举报
回复
CString 是一个对象,你可以先转换成字符串LPCTSTR然后在atoi

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧