1 Attachment(s)
[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.
Re: Problem using map for string
Lose the .h from your string #include
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.
Re: Problem using map for string
Thanks Lindley and GCDEF.
I manage to compile to code already.