Hello,
I have the following code:
std::map<int,st d::set<std::str ing> > k;
k[0]="1234567890 ";
k[1]="2345678901 ";
//...
std::set<std::s tring> myMethod(std::m ap<int,std::set <std::string> > k)
throw(std::runt ime_error)
{
std::map<int,st d::set<std::str ing> >::const_iterat or i;
i=k.find(0);
if(i==k.end())
throw std::runtime_er ror("No zero in k.");
return i->second;
}
Compilation of this code goes well, but I have the following problem while
executing this in my implementation: "Segmentati on fault". I have
pin-pointed the problem to be the last return statement. When I ignore
using find(int) and instead loops over the map with the following code,
everyting goes fine.
std::set<std::s tring> strings;
for(i=k.begin() ;i!=k.end();i++ )
{
if(k->first==0)
strings=k->second;
}
return strings;
Anybody know what is going on here?
Regards,
Peter Jansson
I have the following code:
std::map<int,st d::set<std::str ing> > k;
k[0]="1234567890 ";
k[1]="2345678901 ";
//...
std::set<std::s tring> myMethod(std::m ap<int,std::set <std::string> > k)
throw(std::runt ime_error)
{
std::map<int,st d::set<std::str ing> >::const_iterat or i;
i=k.find(0);
if(i==k.end())
throw std::runtime_er ror("No zero in k.");
return i->second;
}
Compilation of this code goes well, but I have the following problem while
executing this in my implementation: "Segmentati on fault". I have
pin-pointed the problem to be the last return statement. When I ignore
using find(int) and instead loops over the map with the following code,
everyting goes fine.
std::set<std::s tring> strings;
for(i=k.begin() ;i!=k.end();i++ )
{
if(k->first==0)
strings=k->second;
}
return strings;
Anybody know what is going on here?
Regards,
Peter Jansson
Comment