Okay, I know that this wouldn't compile b/c ["one"]["1"] is confusing for the compiler. He may think it's some sort of multidimentional array or something, I guess. Can you tell me who to fix this? I made a dummy:
#include <iostream>
#include <map>
using namespace std;
typedef map<string,map<string, string> > dmap;
int main(){
dmap test;
test.insert(pair< string, pair<string, string> >("one",make_pair("1","a")));
cout << test["one"]["1"];
return 0;
}
145# g++ test2.cpp
/usr/include/c++/3.4/bits/stl_pair.h: In constructor `std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = std::string, _U2 = std::pair<std::string, std::string>, _T1 = const std::string, _T2 = std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >]':
test2.cpp:9: instantiated from here
/usr/include/c++/3.4/bits/stl_pair.h:90: error: no matching function for call to `std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >::map(const std::pair<std::string, std::string>&)'
/usr/include/c++/3.4/bits/stl_map.h:166: note: candidates are: std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]
/usr/include/c++/3.4/bits/stl_map.h:156: note: std::map<_Key, _Tp, _Compare, _Alloc>::map(const _Compare&, const typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, _Alloc>::allocator_type&) [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]
/usr/include/c++/3.4/bits/stl_map.h:148: note: std::map<_Key, _Tp, _Compare, _Alloc>::map() [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]
------------------------------------------------------------
This is the actual real problem, the reason I made the dummy. I know that the dummy program is nothing like the below original problem ( they are not anologies ) but I'd like to still know how to solve the dummy part as well, if members of gameDev can give me a helping hand! :D
typedef std::map<std::string,map<std::string, std::string> > DataMap;
std::map<std::string, std::string> *tempMap;
for( DataMap::reverse_iterator i=controlDirectoryInformation.GetFilesMap().rbegin(); i != controlDirectoryInformation.GetFilesMap().rend(); ++i ){
for ( std::map<std::string, std::string>::iterator j=i->second.begin(); j != i->second.end(); ++j ){
std::cout << "\t\t" << j->first << "=" << j->second << std::endl;
}
std::cout << "[" << i->first << "]"; // this is not a segmentation fault & line 102 (see below for debugger Error)
*tempMap=i->second;
std::cout << (*tempMap)["name"]; // this is a segmentation fault
std::cout << "[" << i->second["name"] << "]"; // this is also a segmentation fault
}
Errors:
Program received signal SIGSEGV, Segmentation fault.
0x0805a46a in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::_M_begin (this=0x0) at stl_tree.h:460
460 { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
(gdb) bt
#0 0x0805a46a in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::_M_begin (this=0x0) at stl_tree.h:460
#1 0x08062b21 in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::clear (this=0x0) at stl_tree.h:658
#2 0x08085742 in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::operator= (this=0x0, __x=@0x80a7894) at stl_tree.h:762
#3 0x08084f08 in std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::operator= (this=0x0, __x=@0x80a7894) at stl_map.h:218
#4 0x08081ff4 in Control::DisplayList (this=0x80a70c0) at Control.cpp:102
#5 0x08058c06 in main (argc=2, argv=0xbfbfec30) at new_shenu.cpp:210
(
---------------------------------------------------------------
while waiting for an answer I tried to make a dummy that actually is an anology of the original problem
#include <iostream>
#include <map>
using namespace std;
typedef map<string,map<string, string> > DataMap;
int main(){
DataMap test;
test.insert(pair< string, pair<string, string> >("one",make_pair("1","a")));
test.insert(pair< string, pair<string, string> >("one",make_pair("2","b")));
test.insert(pair< string, pair<string, string> >("two",make_pair("3","c")));
test.insert(pair< string, pair<string, string> >("two",make_pair("4","d")));
map<string,string> *tempMap;
for( DataMap::reverse_iterator i=test.rbegin(); i != test.rend(); ++i ){
for ( std::map<std::string, std::string>::iterator j=i->second.begin(); j != i->second.end(); ++j ){
std::cout << "\t\t" << j->first << "=" << j->second << std::endl;
}
std::cout << "[" << i->first << "]"; // this is not a segmentation fault & line 102 (see below for debugger Error)
*tempMap=i->second;
std::cout << (*tempMap)["name"]; // this is a segmentation fault
std::cout << "[" << i->second["name"] << "]"; // this is also a segmentation fault
}
//cout << test["one"]["1"];
return 0;
}
and once again defeated by compile Errors: ARRRR
145# g++ test2.cpp
/usr/include/c++/3.4/bits/stl_pair.h: In constructor `std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = std::string, _U2 = std::pair<std::string, std::string>, _T1 = const std::string, _T2 = std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >]':
test2.cpp:9: instantiated from here
/usr/include/c++/3.4/bits/stl_pair.h:90: error: no matching function for call to `std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >::map(const std::pair<std::string, std::string>&)'
/usr/include/c++/3.4/bits/stl_map.h:166: note: candidates are: std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]
/usr/include/c++/3.4/bits/stl_map.h:156: note: std::map<_Key, _Tp, _Compare, _Alloc>::map(const _Compare&, const typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, _Alloc>::allocator_type&) [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]
/usr/include/c++/3.4/bits/stl_map.h:148: note: std::map<_Key, _Tp, _Compare, _Alloc>::map() [with _Key = std::string, _Tp = std::string, _Compare = std::less<std::string>, _Alloc = std::allocator<std::pair<const std::string, std::string> >]
The errors seem to be due to the misuse of make_pair()
I guess maps have different functions to insert like how I tried
--------------------------------------------------------------
So, I try an even more manual method:
#include <iostream>
#include <map>
using namespace std;
typedef map<string,map<string, string> > DataMap;
int main(){
DataMap test;
map<string,string> *tempMap=new std::map;
map.insert(pair< string, string>("1","a") );
test.insert(pair< string, pair<string, string> >("one",*tempMap));
map.insert(pair< string, string>("2","b") );
test.insert(pair< string, pair<string, string> >("one",*tempMap));
map.insert(pair< string, string>("3","c") );
test.insert(pair< string, pair<string, string> >("one",*tempMap));
map.insert(pair< string, string>("4","d") );
test.insert(pair< string, pair<string, string> >("one",*tempMap));
for( DataMap::reverse_iterator i=test.rbegin(); i != test.rend(); ++i ){
for ( std::map<std::string, std::string>::iterator j=i->second.begin(); j != i->second.end(); ++j ){
std::cout << "\t\t" << j->first << "=" << j->second << std::endl;
}
std::cout << "[" << i->first << "]"; // this is not a segmentation fault & line 102 (see below for debugger Error)
*tempMap=i->second;
std::cout << (*tempMap)["name"]; // this is a segmentation fault
std::cout << "[" << i->second["name"] << "]"; // this is also a segmentation fault
}
//cout << test["one"]["1"];
return 0;
}
Encountered more errors. I must be dumb b/c I can't even fabricate a dummy.
Anyway
Errors:
145# g++ test2.cpp
test2.cpp: In function `int main()':
test2.cpp:9: error: `std::map' is not a type
test2.cpp:10: error: missing template arguments before '.' token
test2.cpp:11: error: no matching function for call to `std::pair<std::string, std::pair<std::string, std::string> >::pair(const char[4], std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >&)'
/usr/include/c++/3.4/bits/stl_pair.h:69: note: candidates are: std::pair<std::string, std::pair<std::string, std::string> >::pair(const std::pair<std::string, std::pair<std::string, std::string> >&)
/usr/include/c++/3.4/bits/stl_pair.h:85: note: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
/usr/include/c++/3.4/bits/stl_pair.h:81: note: std::pair<_T1, _T2>::pair() [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
test2.cpp:12: error: missing template arguments before '.' token
test2.cpp:13: error: no matching function for call to `std::pair<std::string, std::pair<std::string, std::string> >::pair(const char[4], std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >&)'
/usr/include/c++/3.4/bits/stl_pair.h:69: note: candidates are: std::pair<std::string, std::pair<std::string, std::string> >::pair(const std::pair<std::string, std::pair<std::string, std::string> >&)
/usr/include/c++/3.4/bits/stl_pair.h:85: note: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
/usr/include/c++/3.4/bits/stl_pair.h:81: note: std::pair<_T1, _T2>::pair() [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
test2.cpp:14: error: missing template arguments before '.' token
test2.cpp:15: error: no matching function for call to `std::pair<std::string, std::pair<std::string, std::string> >::pair(const char[4], std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >&)'
/usr/include/c++/3.4/bits/stl_pair.h:69: note: candidates are: std::pair<std::string, std::pair<std::string, std::string> >::pair(const std::pair<std::string, std::pair<std::string, std::string> >&)
/usr/include/c++/3.4/bits/stl_pair.h:85: note: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
/usr/include/c++/3.4/bits/stl_pair.h:81: note: std::pair<_T1, _T2>::pair() [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
test2.cpp:16: error: missing template arguments before '.' token
test2.cpp:17: error: no matching function for call to `std::pair<std::string, std::pair<std::string, std::string> >::pair(const char[4], std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >&)'
/usr/include/c++/3.4/bits/stl_pair.h:69: note: candidates are: std::pair<std::string, std::pair<std::string, std::string> >::pair(const std::pair<std::string, std::pair<std::string, std::string> >&)
/usr/include/c++/3.4/bits/stl_pair.h:85: note: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
/usr/include/c++/3.4/bits/stl_pair.h:81: note: std::pair<_T1, _T2>::pair() [with _T1 = std::string, _T2 = std::pair<std::string, std::string>]
mmmmmmmmmkkkkkkkkkkkkkkkk...
so.....
these errors seem to be due to
I HATE MAPS NOW!
NO REALLY!!
[Edited by - Tradone on April 24, 2006 5:30:08 PM]