I am looking for some STL (but not boost) container, which after the following operations will contain 2 elements: "abc" and "xyz":
std::XContainer<string> string_XContainer;
string_XContainer.push_back("abc");
string_XContainer.push_back("abc");
string_XContainer.push_back("xyz");
By the way, I need it just in order to call string_XContainer.size()
in the end, to get the total number of unique strings. So maybe I don't even need a container, and there is a more elegant way of doing it?
std::set
is the one you are after. A set will contain at most one instance of each element, compared according to some comparator function you define.
This would be one approach to get the number of unique strings. From your example, the strings were already in sorted order? If that's the case, then you could just create an array (or some other simple structure) and use the std::unique
algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With