我们一般数组的声明和定义放在一起的话,可以写这样的语句:
unsigned char usCharSet[] = {'f' ,'h' ,'h'  ,'r', 'r'};
但是现在我的问题是,如果我在我一个定义的类的头文件声明了
unsigned char usCharSet[10];
那么我怎么在构造函数中对其进行赋值?(数组中的取值是没有规律的)
谢谢指点!!

解决方案 »

  1.   

    不会是只能这样吧?
    usCharSet[0] = 'f';
    usCharSet[1] = 'f';
    usCharSet[2] = 'g';
    usCharSet[3] = 'h';
    ........
      

  2.   

    memcpy(usCharSet, (const void*)"ffgh", 4 );
      

  3.   

    .h
    unsigned char* usCharSet;
    .cpp
    usCharSet new char[10] = { 'a', 'b',....}
      

  4.   

    .h
    unsigned char* usCharSet;
    .cpp
    usCharSet = new char[10] = { 'a', 'b',....}析构
    delete [] usCharSet;
      

  5.   

    lsq004() 希望你不要再发这种广告,我已经删了一个!!!!
      

  6.   

    leiming(unsigned char a[10]){for(int i=0;i<10;i++)
                                           uncharset[i]=a[i];}小见 试试                  
      

  7.   

    to meiko(tiger_mhu) 
    我使用的是数组阿
    应该不用使用new!
    还有没有别的方法?
      

  8.   

    天啊!
    楼上的朋友的话,是不是就像我所想的最坏的情况呢?要这么写呢?
    usCharSet[0] = 'f';
    usCharSet[1] = 'f';
    usCharSet[2] = 'g';
    usCharSet[3] = 'h';
    ........
      

  9.   

    strcpy(str, "Source");
    这个方法确实可以存入字符!
    但是如果我想存入数字,却不可以了
    比如是strcpy(str, "33urce");
      

  10.   

    strcpy  或者memset或者memcpy
      

  11.   

    这样做就可以:
    memset(usCharSet, 0, sizeof(usCharSet));
    strcpy(usCharSet, "your string");搞定!也可以不需要第一行:)
      

  12.   

    meiko是个骗子!他的方法编不过!