
如何实现C++的double向CString的转换2
CStringlist::print(node*lh,node*lt){CStrings;node*n;n=lh;while(n->next!=lt){s+=n->p+"...
CString list::print(node *lh,node *lt)
{
CString s;
node *n;
n=lh;
while(n->next!=lt)
{
s+=n->p+"*"+"x^"+n->e;
n=n->next;
}
return s;
}
这个函数出现错误 error C2111: pointer addition requires integral operand 我想转换为CString 这样就不会出现错误了吧
s.Format(_T("%f"),x);
不明白 那个n->e和n->p都是double 展开
{
CString s;
node *n;
n=lh;
while(n->next!=lt)
{
s+=n->p+"*"+"x^"+n->e;
n=n->next;
}
return s;
}
这个函数出现错误 error C2111: pointer addition requires integral operand 我想转换为CString 这样就不会出现错误了吧
s.Format(_T("%f"),x);
不明白 那个n->e和n->p都是double 展开
2个回答
展开全部
可以使用atof、_gcvt。例子:
#i nclude <stdlib.h>
#i nclude <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 );
}
而将数字转换为CString变量,可以使用CString的Format函数。
如:
CString s;
int i = 64;
s.Format("%d", i)
#i nclude <stdlib.h>
#i nclude <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 );
}
而将数字转换为CString变量,可以使用CString的Format函数。
如:
CString s;
int i = 64;
s.Format("%d", i)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询