[RESOLVED] Problem using map for string
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Problem using map for string

  1. #1
    Join Date
    Apr 2009
    Posts
    82

    [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  

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,047

    Re: Problem using map for string

    Lose the .h from your string #include

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: Problem using map for string

    #include <string.h> is identical to #include <cstring>. It is the C string function header, eg, strcmp(), strcat(), etc.

    #include <string> is entirely different.

  4. #4
    Join Date
    Apr 2009
    Posts
    82

    Re: Problem using map for string

    Thanks Lindley and GCDEF.
    I manage to compile to code already.
    Regards,
    PH Chang

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center