Problème redéfinition opérateur <<
Bonjour,
Voila j'essai de compter le nombre de mot d'un texte avec une map. (histoire de pas comtper deux fois le même mot). Pourtant j'ai une erreur que je ne comprends pas:
Code:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::pair<_Ty1,_Ty2>' (or there is no acceptable conversion)
J'ai pourtant bien redéfini l'opérateur << dans ma classe :(. Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include "CompteMot.h"
CompteMot::CompteMot ()
{
}
CompteMot::~CompteMot ()
{
}
void CompteMot::comptage ()
{
std::map<std::string, int, std::less<std::string> > dico;
std::string mot;
std::ostream_iterator<std::pair<const std::string, int> > outDate (std::cout, " ");
std::copy (dico.begin (), dico.end (), outDate);
while (std::cin >> mot)
{
if (dico.find (mot) != dico.end ())
{
++(*(dico.find (mot))).second;
}
else
{
dico[mot] = 1;
}
}
std::copy (dico.begin (), dico.end (), outDate);
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #ifndef COMPTEMOT_H
#define COMPTEMOT_H
#include <map>
#include <iterator>
#include <iostream>
#include <string>
class CompteMot
{
public:
CompteMot ();
virtual ~CompteMot ();
virtual void comptage ();
};
inline std::ostream& operator<<(std::ostream& os, const std::pair<const std::string, int>& p)
{
os << p.first << " " << p.second << std::endl;
return os;
}
#endif |
Si quelqu'un vois ce qu'il ne va pas merci d'avance :)