数组可以指定长度,char d[10],CString对象怎么指定长度?

解决方案 »

  1.   

    char d[10]说的是10个char型的数据
    CString str[10]说的是10个CString型的数据不知你要问占内存的长度,还是什么样的长度
      

  2.   

    CString::PreAllocateMem  好像是这个
      

  3.   

    那么用SetAt(i,'a')怎么会出错?//如int i = 3;
      

  4.   

    CString 是对字符串封装的一个类,他可以是很多个字符但是他的效率不是很高当有很多个字符串的时候比如说超过256个字符,推荐使用char sz[256];
      

  5.   

    char d[10]说的是10个char型的数据
    CString 不需要指定长度。那么用SetAt(i,'a')怎么会出错?//如int i = 3;
    要保证这个String的长度在4个字符以上,才可以
      

  6.   


    要保证这个String的长度在4个字符以上,才可以保证,怎么保证?不还是初始或者指定它的长度吗?
      

  7.   

    你可以使用该构造方法实现指定CString的长度:
    CString str("", nLength);
    nLength 就是你需要的长度,如1024
      

  8.   

    CString s6( 'x', 6 );          // s6 = "xxxxxx"
      

  9.   

    void SetAt( int nIndex, TCHAR ch );ParametersnIndexZero-based index of the character in the CString object. The nIndex parameter must be greater than or equal to 0 and less than the value returned by GetLength. The Debug version of the Microsoft Foundation Class Library will validate the bounds of nIndex; the Release version will not.chThe character to insert.
      

  10.   

    CString  str(  "  ",  nLength); 
    在“ ”内有一个NULL,所以下一次得到它的长度时,就是“ ”内NULL前的长度,
    所以用‘ ’比较好。