Since the size of the file is unknown you need to use vectors to store the
data. I also suggest you to read in the file into a string , from start untill
you reach the ',' comma character. Therefore you will need to use a
vectors of strings.
std::vectors<std::string> contents;
Then you read until the comma character is reached :
std::string tmp;
getline(readFile,tmp,','); //read until the comma character is reached
Of course you will need to read the file until it ends so you need to while
loop it.
while( readFile.good() ){
std::string temp;
getline(readFile,temp,',');
content.push_back( temp ); //add it to our list
}
So by now we have all of the content in the file stored inside our vectors
of string. Now all that is needed is to sort the vector. Maybe instead
of using the std::sort method, you should research on the art of sorting.
It will be a good learning experience. The after you have a sorting
code working, all you have to do is to make sure that you are
sorting the vector with respect to the length of its content.