String with changing number?

Hi, I'm having trouble writing a code that will make a list of strings that have an increasing number at the end of it (ex.The output would be example_1, example_2, example_3 etc.) Can anyone help?
Thanks
1
2
3
4
5
6
7
8
9
  string Base = "example_";
  string Form;

  for( int i = 1; i < MAX; ++i )
  {
    Form = Base;
    Form += i;
    cout<<Form.c_str()<<endl;
  }
Thanks, this works for the most part.
The number at the end (i) is in ASCII though. How do I make it a number so that I can count past single digits?
Hm.. I must be rusty for some reason I thought it would convert. Silly me.

Using itoa

1
2
3
4
5
6
7
8
9
10
11
  char Buff[5];
  string Base = "example_";
  string Form;

  for( int i = 1; i < MAX; ++i )
  {
    Form = Base;
    itoa(i,Buff,10);  
    Form += Buff;
    cout<<Form.c_str()<<endl;
  }

Thanks, this worked perfectly.
If you don't mind me asking, what does itoa do?
itoa

i = int
to = to
a = alphabet

Takes an int and changes it to the correct ascii symbols.

There are other ones like atoi, atof, ftoa, etc.
Topic archived. No new replies allowed.