CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    116

    [RESOLVED] Problem using map for string

    I have problem assigning value to mymap for string which I don't understand why. A lot of compile errors came out. However, when I try to map int, I have no problem assigning them.

    Code:
    #include <string.h>
    #include <iostream>
    #include <map>
    #include <utility>
    	 
    using namespace std;
     
    int main()
    {
    	  map<string, int> mymap;
    	  mymap.insert(make_pair("John",123));
    
    	   return 0;
    
    }
    Some of the compile error:
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
    c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): error C2784: 'bool std:: operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
    ...

    See attached image for more detail on compile errors.
    Attached Images Attached Images

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured