Thread: String Class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Thank you, but "problems" are so generic. Learn to be a little more descriptive and not make others do so much of your work.

    Try this:

    Code:
    const String & String::operator +=(const String & str)
    {
    	int newsize = getLength() + str.getLength() + 1; // Size of current + new string + '\0'.
    	char *temp = NULL;
    	if(newsize > size)
    	{
    		temp = new char[newsize];
    		strcpy(temp, buf);
    		delete []buf;
    		buf = temp;
    		size = newsize;  // Accidentally left this out.
    	}
    	strcat(buf, str.buf);
    	stringlength = newsize;
    	return *this;
    }
    Disclaimer: I'm really more of a C programmer, so check it over to make sure I didn't break anything.
    Last edited by MacGyver; 08-01-2007 at 11:09 PM. Reason: Accidentally left out setting var size.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. class object manipulation
    By guda in forum C++ Programming
    Replies: 2
    Last Post: 10-09-2004, 10:43 AM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM