Thread: change variable and repeat

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    12

    change variable and repeat

    i want to do the same thing to several variables such as xword1, xword2, xword3...They are all the same type and in my case usually a string. is there a way that i can do something like xword[i] to shorten my code. or a way to use recursion for this? it would be really nice if it was something that worked with my string::iterators, but if not then i will work around it.


    Code:
    for (ix = p1xword1.begin(); ix < p1xword1.end(); ix++){
    					p1curWord1 += "*";

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I'm guessing you haven't learned about arrays yet? Because that's exactly what you need:
    Example:
    Code:
    int numbers[5];
    for ( int i = 0; i < 5; ++i )
    {
       numbers[i] = i;
    }
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    12
    i dont know why i didnt think of using a string array. i was already overloading the strings but it worked and i can still overload them.

    thank you so much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vector<...>::iterators and insert - I'm stumped.
    By Dino in forum C++ Programming
    Replies: 6
    Last Post: 12-25-2007, 06:11 AM
  2. repeat loop
    By taurus in forum C Programming
    Replies: 14
    Last Post: 09-11-2007, 07:31 AM
  3. value of char variable with loops
    By david999 in forum C Programming
    Replies: 5
    Last Post: 11-03-2005, 01:55 PM
  4. Making your prgram repeat
    By chibby2 in forum C++ Programming
    Replies: 1
    Last Post: 07-03-2005, 11:14 AM
  5. How does cin actually work
    By blueCheese in forum C++ Programming
    Replies: 5
    Last Post: 04-16-2004, 08:44 AM

Tags for this Thread