Converting an integer array to a string array

Jun 30, 2011 at 3:31pm
Hi,

I am trying to convert an integer array (with six entries) to a string array. My code is the following

(run[] is an integer array.)

1
2
3
4
5
6
7
8
9
10
11
                                                                                   
stringstream out;
string carray[6];

for (int k = 5; k > -1; k--)
{
    out << run[k];
    carray[k] = out.str()
}

cout << carray << endl;


The problem is when I print the array, I get a bunch of random letters and numbers.

I have tested run[] with a for loop to print out the array, and it is indeed a number array with the proper entries.

Thanks!

fertileneutrino
Jun 30, 2011 at 3:49pm
carray is an array of six strings. Pick which one you want to output, and output that.

For example,

cout << carray[0] << endl;
Last edited on Jun 30, 2011 at 3:49pm
Jun 30, 2011 at 3:51pm
is run defined as char or int?
Topic archived. No new replies allowed.