Hello! I have a problem that needs me to load a char array from a file, make every line of that array into a string, and then sort the strings.
EX:
bgtf
bhgy
acfg
cfgg
needs to turn into
acfg
bgtf
bhgy
cfgg
I have the character array loaded fine, I am just not sure how to turn it into four different strings that I can then sort?
The actual problem uses a [10][15] array. So I was trying to figure out a way to use a for loop to create the strings. I think I may just be ignorant to some part of string properties. I have all the libraries included.
Bottom line for now, I just need to figure out how to "load" a new string value with a range of chars.
Thanks!
To illustrate a little more... in my mind I am trying to do this:
string line1(array[0][0-3]) in order to get line1="bgtf" (from the top array)
Obviously this isn't working for me, and I am pretty sure I am just doing it wrong and lack the proper syntax.
#include <cstdlib> //rand(), srand() - wont need
#include <ctime> // time() - wont need
#include <algorithm> //will need (std::sort())
int main()
{
srand(time(NULL));
char strings[10][15] = {0};
//Initialize string with random chars;
for(auto& a : strings)
for(auto& i : a)
i = rand() % 256;
//sort them
for(auto& a : strings)
std::sort(a, a+15);
}