Hello

I have little problem with my code.
Problem is iterator inner.
How can i solve this?

My code

map <string, map <string, string> > m;
map <string, map <string, string> >::iterator outer;
map <string, string>::iterator inner;

m["John"]["VW"]="Golf";

inner=m.find("VW");

if(inner != m.end())
{cout<<inner->second<<endl;}

Best Regards
Danijel

'm' seems to be expecting to map a string to a map<string,string>, but you are trying to tell it to map a string to a string. "Problem is iterator inner" - can you be a lot more specific? Is there a compiler error?

Dave

"Problem is iterator inner" - can you be a lot more specific? Is there a compiler error?

Outer works good.
Inner must find "VW" and return second string "Golf"

outer=m.find("John");
if(outer != m.end())
  {cout<<outer->first<<endl;}
   
inner=m.find("VW");
if(inner != m.end())
{cout<<inner->second<<endl;}

Here is compiler error

maptest.cpp: In function ‘int main()’:
maptest.cpp:18: error: no match for ‘operator=’ in ‘inner = m.std::map<_Key, _Tp, _Compare, _Alloc>::find [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _Compare = std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(& std::basic_string<char, std::char_traits<char>, std::allocator<char> >(((const char*)"John"), ((const std::allocator<char>&)((const std::allocator<char>*)(& std::allocator<char>())))))))’
/usr/include/c++/4.4/bits/stl_tree.h:154: note: candidates are: std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >& std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::operator=(const std::_Rb_tree_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)

Best Regards
Danijel

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.