[Dev-C++] problem with iteration in map
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: bhadram r. <bha...@ya...> - 2005-08-26 07:05:39
|
Dear frinends,
I'd a problem. The problem is that I want to know how to iterate through the map if i am iterating like those in code there problems like '=' cannot find the overload operator etc.. How to solve this problem .Also i want to know the importance of allocator. why it is used. why it is only used in iterator rather than in map definition.
Please help me.
Thanking you,
yours sincerely,
bhadram
# include <map>
# include<string>
# include <iostream>
using namespace std;
void main()
{
map<string,string > trans_map;
typedef map<string,string >::value_type valType;
trans_map.insert( valType( "gratz", "grateful" ));
trans_map.insert( valType( "'em", "them" ));
trans_map.insert( valType( "cuz", "because" ));
trans_map.insert( valType( "nah", "no" ));
trans_map.insert( valType( "sez", "says" ));
trans_map.insert( valType( "tanx", "thanks" ));
trans_map.insert( valType( "wuz", "was" ));
trans_map.insert( valType( "pos", "suppose" ));
map<string,less<string>,allocator<string> >::iterator iter;
map<string,less<string>,allocator<stirng> >::iterator iter_end=trans_map.end();
for(iter=trans_map.begin();iter!=iter_end;iter++)
{
cout<<(*iter).first<<" "<<(*iter).second<<endl;
}
}
errors are :
D:\cpppractice\aug22\textcpp.cpp(21) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::_Tree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::pair<
class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,struct std::map<class std::basic_string<char,struct std::char_tr
aits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::all
ocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::_Kfn,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<class std::basic
_string<char,struct std::char_traits<char>,class std::allocator<char> > > >::iterator' (or there is no acceptable conversion)
D:\cpppractice\aug22\textcpp.cpp(21) : error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::_Tree<_K,_Ty,_Kfn,_Pr,_A>::iterator' (or there is no acceptable conversion)
D:\cpppractice\aug22\textcpp.cpp(23) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >' (or there is
no acceptable conversion)
Error executing cl.exe.
textcpp.obj - 6 error(s), 14 warning(s)
---------------------------------
Start your day with Yahoo! - make it your home page |