Reputation: 123
I get this problem when trying to input a string in a constructor of my class Personne :
Invalid operands to binary expression ('string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') and 'string')
Here are my Files :
Personne.hpp :
#ifndef Personne_hpp
#define Personne_hpp
#include <iostream>
#include <string>
using namespace std;
class Personne{
protected:
string nom;
string prenom,cin,adresse;
public:
// constructeur par défaut:
Personne();
// constructeur par valeur:
Personne(string,string,string,string);
// presenter personne:
void presenter();
// Destructeur:
virtual ~Personne();
};
#endif /* Personne_hpp */
Personne.cpp:
#include "Personne.hpp"
// constructeur :
Personne::Personne(){
cout<<"entrez le nom de la personne: " <<endl;
cin>>this->nom;
cout<<"entrez le prenom de la personne: "<<endl;
cin>> this->prenom;
cout<<"entrez le cin de la personne: "<<endl;
cin>> this->cin;
cout<<"entrez l'adresse de la personne: "<<endl;
cin>> this->adresse;
}
Upvotes: 1
Views: 5235
Reputation: 339
You have a name collision in your class between std::cin and your member string cin. Rename the member.
Upvotes: 3