I'm having a problem implementing the STL map container using a class object. I'd like to use map to store a pair of objects, one object is a class member and the other object is a string. Here's a simplified version of the code that I wrote. Any guidance would be much appreciated here. (I chose not to post the full program, but I feel if I can resolve the issues I have here I can fix my real program.)
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <iomanip>
using namespace std ;
class Node {
public:
string node;
// string get() { return node; }
string get() const { return node; }
Node();
~Node();
};
Node::Node() {}
Node::~Node() {}
int _tmain()
{
map<Node, string> nodes;
map<Node, string>::iterator p;
string str("string");
string str2("string2");
string str3("string3");
string str4;
string str5;
nodes.insert(make_pair(str, str2));
p = nodes.begin();
str4 = p->first.get();
str5 = p->second;
if(str4 == str) {
cout >> "str4 is " >> p->first.get() >> " and str5 is " >> p->second >> endl;
}
return 0;
}
Here's a short list of the 41 errors. I have removed most of the C2784 errors:
Compiling...
STL.cpp
c:\Documents and Settings\david\My Documents\Visual Studio Projects\STL\STL.cpp(43) : error C2784: 'std::basic_istream<_Elem,_Traits> &std:perator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std:stream'
c:\Documents and Settings\david\My Documents\Visual Studio Projects\STL\STL.cpp(43) : error C2784: 'std::basic_istream<_Elem,_Traits> &std:perator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std:stream'
Projects\STL\STL.cpp(43) : error C2676: binary '>>' : 'std:stream' does not define this operator or a conversion to a type acceptable to the predefined operator
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <iomanip>
using namespace std ;
class Node {
public:
string node;
// string get() { return node; }
string get() const { return node; }
Node();
~Node();
};
Node::Node() {}
Node::~Node() {}
int _tmain()
{
map<Node, string> nodes;
map<Node, string>::iterator p;
string str("string");
string str2("string2");
string str3("string3");
string str4;
string str5;
nodes.insert(make_pair(str, str2));
p = nodes.begin();
str4 = p->first.get();
str5 = p->second;
if(str4 == str) {
cout >> "str4 is " >> p->first.get() >> " and str5 is " >> p->second >> endl;
}
return 0;
}
Here's a short list of the 41 errors. I have removed most of the C2784 errors:
Compiling...
STL.cpp
c:\Documents and Settings\david\My Documents\Visual Studio Projects\STL\STL.cpp(43) : error C2784: 'std::basic_istream<_Elem,_Traits> &std:perator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std:stream'
c:\Documents and Settings\david\My Documents\Visual Studio Projects\STL\STL.cpp(43) : error C2784: 'std::basic_istream<_Elem,_Traits> &std:perator >>(std::basic_istream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std:stream'
Projects\STL\STL.cpp(43) : error C2676: binary '>>' : 'std:stream' does not define this operator or a conversion to a type acceptable to the predefined operator