#include <iostream>
usingnamespace std;
class Prob
{
public:char nameProb[256];
public:Prob(char*name,int number)
{//in this array we will store the converted integer
char n[256];
//function that converts integers to ascii ("integer to ascii"), third parameters describes the numerical base (decimal in this case:10)
itoa(number,n,10);
strcpy(nameProb,name);
strcat(nameProb,n);
cout<<nameProb<<endl;
}
};
int main()
{ Prob* probArray[100];
for(int i=0;i<100;i++)
{probArray[i]=new Prob("test",i);
}
cin.get();
}
for the first replay from Nicolas, it still dose not work because my cygwin compiler can not regognaize the function itoa(). I have searched in this website for this function and found that there is alternative for it namly sprintf(). But this function can not convert int to char...
my initial posting was with string streams but if you want to use spritf you can use something like this
1 2 3 4 5 6 7
char buff[2]; // to hold int
char name[256]="test-"; // or whatever you like
int i=1;
sprintf(buff,"%d",i); // convert int to chars
strcat(name,buff); // concatenate