如何实现C++的double向CString的转换2

来源:百度知道 编辑:UC知道 时间:2024/05/22 10:12:04
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

可以使用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)

CString s;
s.Format(_T("%f"),x);