I have a char array, in which its contents look something like the following:
char buffer[] = "I1 I2 V1 V2 I3 V3 I4 DO V4";
As you may see, it’s a typical blank separated character string. I want to put all sub-string(s) starting with a letter “I” into a vector (IVector), and sort its elements in ascending order. At the same time, I’d also want to put all sub-string(s) starting with a letter “V” into another vector (VVector), and sort its elements in ascending order. The other(s) (e.g. “DO” in this example) will be ignored.
I’m not familiar with STL algorithm library. Are there any functions to help me achieve the avove-mentioned job?
Thank you!
You can iterate over all the substrings using an
std::istream_iterator<std::string>:Then you can use
std::sortto sort the vectors, as @Billy has already pointed out. You could also consider using anstd::set, as that will always keep your items sorted in the first place.