It's me again.........I need help once more. (Very short)

This is a discussion on It's me again.........I need help once more. (Very short) within the C++ Programming forums, part of the General Programming Boards category; Code: void String::operator+=(const String& rhs) { unsigned short rhsLen = rhs.GetLen(); unsigned short totalLen = itsLen + rhsLen; String temp(totalLen); ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    It's me again.........I need help once more. (Very short)

    Code:
    void String::operator+=(const String& rhs)
    {
    	unsigned short rhsLen = rhs.GetLen();
    	unsigned short totalLen = itsLen + rhsLen;
    	String  temp(totalLen);
    	unsigned short i;
    	for (i = 0; i<itsLen; i++)
    		temp[i] = itsString[i];
    	for (unsigned short j = 0; j<rhs.GetLen(); j++, i++)
    		temp[i] = rhs[i-itsLen];
    	temp[totalLen]='\0'; What is this doing here? is it assigned the value of totalLen, meaning the the two strings to temp or what?
    	*this = temp;
    }
    Last edited by incognito; 01-25-2002 at 06:19 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    Unregistered
    Guest
    It adds \0 to the end of the character array. This is known as the terminating character. All strings have this at the end of them.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    sorry, forgot to sign in.

  4. #4
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    Ok, besides that isn't temp[totalLen]='\0' doing something else besides that? I mean temp[totalLen] isn't this assigning the value of totalLen to temp or something or is this giving it access to the string at totalLen? Something anything else besides the fact that it's adding the new line character to it.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  5. #5
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    It's saying that the character at position totalLen in the string is equal to the string-termination character.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing Structures Inside Structures
    By Mellowz in forum C Programming
    Replies: 1
    Last Post: 01-13-2008, 02:55 AM
  2. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 03:48 PM
  3. Say what? - Weird error.
    By Blackroot in forum C++ Programming
    Replies: 6
    Last Post: 08-15-2006, 11:54 PM
  4. Help with mult-dim arrays and pointers to them
    By skybolt_1 in forum C Programming
    Replies: 11
    Last Post: 05-02-2003, 11:47 AM
  5. Color Variety
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 10-23-2002, 09:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21