is it possible to insert a new element to std::set like in case of std::list for example:
//insert one element named "string" to sublist of mylist
std::list< std::list<string> > mylist;
mylist.push_back(std::list<string>(1, "string"));
Now, mylist has one element of type std::string in its sub-list of type std::list.
How can you do the same in if std::set is the sub-set of std::list my list i.e
std::list<std::set <string>> mylist;
if you can't then why not?
I think this should do the trick:
int main()
{
string s = "test";
set<string> mySet(&s, &s+1);
cout << mySet.size() << " " << *mySet.begin();
return 0;
}
For clarification on the legality and validity of treating &s
as an array, see this discussion: string s; &s+1; Legal? UB?
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