在EVC中如何将CString转换成int或者double类型?

situju 2006-02-18 06:52:06
CString str1 = "653";
CString str2 = "32.65892";
请问如何将上面两个变量转换成653和32.65892?
谢谢
...全文
371 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
luocolor 2006-03-05
  • 打赏
  • 举报
回复
xuexi
shmily1280 2006-02-22
  • 打赏
  • 举报
回复
WIN CE 的字符是UNICODE的
所以
int n = _wtoi(str1);
double d = wcstod(str2,NULL);
slyzhang 2006-02-20
  • 打赏
  • 举报
回复
Example

/* STRTOD.C: This program uses strtod to convert a
* string to a double-precision value; strtol to
* convert a string to long integer values; and strtoul
* to convert a string to unsigned long-integer values.
*/

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

void main( void )
{
char *string, *stopstring;
double x;
long l;
int base;
unsigned long ul;
string = "3.1415926This stopped it";
x = strtod( string, &stopstring );
printf( "string = %s\n", string );
printf(" strtod = %f\n", x );
printf(" Stopped scan at: %s\n\n", stopstring );
string = "-10110134932This stopped it";
l = strtol( string, &stopstring, 10 );
printf( "string = %s", string );
printf(" strtol = %ld", l );
printf(" Stopped scan at: %s", stopstring );
string = "10110134932";
printf( "string = %s\n", string );
/* Convert string using base 2, 4, and 8: */
for( base = 2; base <= 8; base *= 2 )
{
/* Convert the string: */
ul = strtoul( string, &stopstring, base );
printf( " strtol = %ld (base %d)\n", ul, base );
printf( " Stopped scan at: %s\n", stopstring );
}
}
Output

string = 3.1415926This stopped it
strtod = 3.141593
Stopped scan at: This stopped it

string = -10110134932This stopped it strtol = -2147483647 Stopped scan at: This stopped itstring = 10110134932
strtol = 45 (base 2)
Stopped scan at: 34932
strtol = 4423 (base 4)
Stopped scan at: 4932
strtol = 2134108 (base 8)
Stopped scan at: 932
slyzhang 2006-02-20
  • 打赏
  • 举报
回复
strtol, wcstolSee Also
atof
Convert strings to a long-integer value.

Routine Required Header
strtol <stdlib.h>
wcstol <stdlib.h>

long strtol( const char *nptr, char **endptr, int base );
long wcstol( const wchar_t *nptr, wchar_t **endptr, int base );
Parameters
v111v111 2006-02-20
  • 打赏
  • 举报
回复
网上搜索一下,很多地方都有
situju 2006-02-20
  • 打赏
  • 举报
回复
int n = atoi(str1 );
double d = atof(str2);
只能得到str1和str2的首位数字,下面的就得不到了
yangyzqo 2006-02-19
  • 打赏
  • 举报
回复
晕,这些问题已经有人问过了,你去查查以前的贴子看看
社会栋梁 2006-02-19
  • 打赏
  • 举报
回复
int n = atoi(str1 );
double d = atof(str2)

19,500

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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