怎样用引用进行字符串交换,比如
char *ap="hello";
char *bp="how are you";
交换后
ap:"how are you"
bp:"hello"

解决方案 »

  1.   

    不能进行交换 他们是静态数组
    要这么用
    char ap[100] = "hello";
    char bp[100] = how are you";
    char tmp[100];
    strcmp(tmp,ap);
    strcmp(ap,bp);
    strcmp(bp,tmp);
      

  2.   

    void swapx(char* &x,char* &y)
    {
    char* temp=x;
    x=y;
    y=temp;
    }
    swapx(ap,bp);
      

  3.   

    char* cp
    strcopy(cp,ap);
    strcopy(ap,bp);
    strcopy(bp,cp);
      

  4.   

    听lit_river(小河)的,加上delete语句。