Why can't I insert or delete the inside element of set<set<string>>?
Hi, I was using the STL set as follows and what I want to do here is to
change mySet from {{"Hi", "Hello world to"}, {"A", "B"}} to {{"Hello
world to"},{"A","B"}}, but it fails to compile. Why? And how can I
manage to achieve my goal?Thanks.
====================================================================================
#include <iostream>
#include <set>
#include <string>
using std::set;
using std::string;
void func()
{
set< set<string> > mySet;
....// Initializing mySet, and it is like {{"Hi", "Hello world
to"}, {"A", "B"}}
set< set<string> >::iterator iter = mySet.begin();
iter->erase("Hi"); //There is a complile error here
}
int main()
{
//.......
return 1;
}
The compiler complains about:
passing `const std::set<std::string,
std::less<std::string>, std::allocator<std::string> >' as `this'
argument of
`std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>,
_Compare, _Alloc>::const_iterator, bool> std::set<_Key, _Compare,
_Alloc>::insert(const _Key&) [with _Key = std::string, _Compare =
std::less<std::string>, _Alloc = std::allocator<std::string>]'
discards
qualifiers
===============================================================================
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]