If you have tried to use some STL containers with GCC, such as hash_map:
// error: hash_map: No such file or directory
#include <hash_map>
int main()
{
// error: ‘hash_map’ is not a member of ‘std’
std::hash_map<int,int> hm;
return 0;
}
Then you have realized that the code above does not compile. That's because on GCC, hash_map is not regarded as a standard container, but rather as a extension included in the __gnu_cxx namespace. In order to use hash_map and other extended containers with a minimum impact in your code (which is very important if it's intended to be cross-platform), you can use the following solution:
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
namespace std
{
using namespace __gnu_cxx;
}
int main()
{
std::hash_map<int,int> hm;
return 0;
}
Hope that helps.
#include <iostream>
#include <string>
#ifdef __GNUC__
#include <ext/hash_map>
#else
#include <hash_map>
#endif
namespace std
{
using namespace __gnu_cxx;
}
int main()
{
using namespace std;
hash_map<int, string> mapStudent;
mapStudent.insert(hash_map<int, string>::value_type (1, "student_one"));
mapStudent.insert(hash_map<int, string>::value_type (2, "student_two"));
mapStudent.insert(hash_map<int, string>::value_type (3, "student_three"));
hash_map<int, string>::iterator iter;
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
{
cout<<iter->first<<" "<<iter->second<<endl;
}
return 0;
}