I am using cPP primer to learn the class. When I use vs code to do exercises after the book, I encounter a mistake and don"t know how to solve it.
this is the related code, and the title requires "add the correct constructor to the Person class"
-sharpinclude<iostream>
-sharpinclude<string>
using namespace std;
class Person
{
private:
string strName;
string strAddress;
public:
Person() = default;
Person(const string &name,const string &add)
{
strName = name;
strAddress = add;
}
Person(std::istream &is) { is >> *this; }
public:
string getName() const { return strName; }
string getAddress() const { return strAddress; }
std::istream &read(std::istream &is, Person &per)
{
is >> per.strName >> per.strAddress;
return is;
}
std::ostream &print(std::ostream &os, const Person &per)
{
os << per.getName() << per.getAddress ();
return os;
}
};
error occurs here at run time
code is entered according to the answers to the after-class exercises. I don"t know how to solve the error. I want to ask the boss to solve it. Thank you very much.