Feb 18, 2011 at 2:26pm UTC
All,
I'm having trouble trying to find a way to sort a char array, i've created the array as per below:
ColourArray[0] = "orange";
ColourArray[1] = "green";
ColourArray[2] = "white";
ColourArray[3] = "purple";
ColourArray[4] = "yellow";
ColourArray[5] = "pink";
There seems to be many different ways to sort int arrays but not char (I've tried change the types over to char but did not work)
Could someone possibly point me in the right direction.
Thanks
C.
Feb 18, 2011 at 2:29pm UTC
Assuming by "char array", you meant a vector<string> (if you didn't, you do now):
sort(ColourArray.begin(),ColourArray.end());
Feb 18, 2011 at 2:31pm UTC
If it's a raw array, you can still sort it by passing the equivalent values:
sort(ColourArray, ColourArray + size);
Feb 18, 2011 at 2:43pm UTC
Only if it's a std::string array, though.
Feb 18, 2011 at 4:05pm UTC
Thanks everyone, I'll take a look and try this approach.
Much appreciated.
C.