I'm writing a C++ program that uses the RRD libraries that require an array of 'const char*' for their functions. I thought I could just declare the array, and then initialize each element of the array, but changing one, changes all of them. Obviously I'm missing something. Here's an example similar to the code I am writing (i.e. it exhibits the same problem).
string intToString(long i)
{
stringstream ss;
string s;
ss << i;
s = ss.str();
return s;
}
int main(){
const char* av[5];
int i = 0;
int j = 0;
for(i=0;i<5;i++){
j= 0;
av[i] = intToString(i).c_str();
for(j=0;j<5;j++){ cout << j << " : " << av[j] << endl;}
}
}
Any help would be appreciated.