char * tt =new char[10] ;
CString ss;
ss.Format("%d",strlen(tt));
MessageBox(ss);    //显示14,为什么不是10
delete[] tt;

解决方案 »

  1.   

    char * tt =new char[10] ;
    char[10]='\0';//加上这一句
    CString ss;
    ss.Format("%d",strlen(tt));
    MessageBox(ss);    //显示10
    delete[] tt;
      

  2.   

    非常感谢 ,马上给分
    小弟以前干delphi的,现在闹非典不敢出门,所以闭关修炼vc
    会有很多问题请你以及各位高手指教的
      

  3.   

    char[10]='\0';//加上这一句
    倒是运行结果对了,但是执行到 delete[] tt; 就报错了,不解
      

  4.   

    我觉得应该是
    加上 char[9]='\0' 
    显示9就对了
      

  5.   

    应该是加上 char[9]='\0'
    因为从0--9共10位。
      

  6.   

    char[10]中只有0-8是存储数据的第10位(--9)为结束标志。