Thread: Concatenate string and int

  1. #1
    Registered User
    Join Date
    Sep 2009

    Concatenate string and int

    It is any way to concatenate a string and an integer? I want to add a loop iteration number to the end of a string. Something like 'strcat' would be handy but that only works with strings.

    I would like an like an output something like:

    for (i=0; i<3; i++)
         str = "Num0"  
    The number at the end of str increments after each iteration.

  2. #2
    Registered User
    Join Date
    Jan 2010
    You could use
    sprintf(str, "Num%d", i);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM