1

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;
}
1

1 Answer 1

3

You have a name collision in your class between std::cin and your member string cin. Rename the member.

Sign up to request clarification or add additional context in comments.

3 Comments

And stop using using namespace std
thank you I just find it more easy to write.. does it make a lot of problems to use the namespace instead of std:: ?
In the grand scheme of things no... But, as you just experienced, it can cause confusion...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.