Thread: Need some more help this time with Pointer help

  1. #1
    Registered User
    Join Date
    Sep 2009
    Location
    california
    Posts
    8

    Need some more help this time with Pointer help

    k so im working on putting the value (what is being pointed to) from a pointer and adding
    it to the end of a string.

    Code:
    STRING& STRING::operator+=(char* c)
    {
        char* Temp = new char [Len+1];
        for (unsigned I= 0; I <Len; I++){
            Temp [I]= STR[I];
        }
        Len+=1;
        
        Temp[Len]=char(c); // this is where im trying to add the pointer
        
        delete [] STR;
        STR = Temp;
        return *this;
    }

  2. #2
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    If this is the overload that only adds a single character, then you need to change your code:

    Code:
    STRING& STRING::operator+=(char* c) // Remove part in red
    {
        char* Temp = new char [Len+1];
        for (unsigned I= 0; I <Len; I++){
            Temp [i]= STR[i];
        }
        Len+=1;
        
        Temp[Len]=char(c); // this is where im trying to add the pointer
        
        delete [] STR;
        STR = Temp;
        return *this;
    }
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  4. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

Tags for this Thread