samedi 30 mai 2015

Why does this hashtable function shows a compilation error?

#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

int main (void)
{
    unordered_map<string,string> myhash;
    int i,n,m,len1,len2;
    cin>>n>>m;
    string arr2[3010];
    string s1,s2;
    for ( i = 0; i < m; i++ )
    {
        cin>>s1>>s2;
        myhash.emplace(s1,s2);
    }
    for ( i = 0; i < n; i++ )
    {
        cin>>arr2[i];
    }
    for ( i = 0; i < n; i++ )
    {
        len1 = arr2[i].length();
        len2 = myhash[arr2[i]].length();
        if ( len1 > len2 )
            cout<<myhash[arr2[i]]<<"\t";
        else
            cout<<arr2[i][0]<<"\t";
    }
    cout<<"\n";
    return 0;
}

On compilation, it shows an error.

error: no member named 'emplace' in
      'std::__1::unordered_map<std::__1::basic_string<char>, std::__1::basic_string<char>,
      std::__1::hash<std::__1::basic_string<char> >,
      std::__1::equal_to<std::__1::basic_string<char> >, std::__1::allocator<std::__1::pair<const
      std::__1::basic_string<char>, std::__1::basic_string<char> > > >'
                myhash.emplace(s1,s2);

I made the above code in which I am taking input a number of strings and adding them to the hashtable named myhash. Why do I see this error? Is it because my compiler doesn't support emplace function?

Aucun commentaire:

Enregistrer un commentaire