当然了sizeof(ddd.cdata)得到的是指针的大小,指针都是4个字节的

解决方案 »

  1.   

    对指针调用 sizeof 运算符不会返回指针指向的内存块大小,而是返回指针的大小 ———— 在 32 位的平台下这意味着一个 32 位的地址,也就是 4 个字节。所以你面对的情况是正常的,完全没有错误。
      

  2.   

    不是没分配
    而是你的字符串长度为0
    所以用sizeof()取得的长度只有一个'\0'的空间
      

  3.   

    我也做了试验
    char tt[30];
    查看sizeof(tt);
    得到的结果可是30呀。
      

  4.   

    看来我错了
    指针大小为4
    取字符串长度你试试用CString类型
      

  5.   

    需要加 #include <string.h>
      

  6.   

    When applied to a structure type or variable, sizeof returns the actual size, which may include padding bytes inserted for alignment. When applied to a statically dimensioned array, sizeof returns the size of the entire array. The sizeof operator cannot return the size of dynamically allocated arrays or external arrays.你也可以试试自己写个判断长度的函数
    int mysizeof(char *str)
    {
          int i;
          for(i=0;*(str+i)!='\0';i++);
          return i;
    }
      

  7.   

    new (30*sizeof(char));
    或许可以!
    你可以尝试以下!!
    别拉下
    delete也!!否则!!
      

  8.   

    你需要这样定义结构:
    struct stru
    {
        char*pData;
        ULONG uDataSize;
    };
    使用:
    memset(&stru,0,sizeof(stru));//清0stru.pData = new char[30];
    stru.uDataSize = 30;