You look a bit confused.
As already suggested, you should avoid
I/O
calls in your
class
, on the contrary, the
main
function should collect input from the user, call the object constructor and produce the output based on the object properties (publicly exposed as methods).
Try, for instance
#include<iostream>
using namespace std;
class Person
{
string name;
string job;
int age;
public:
Person(string name, string job, int age) : name{name}, job{job}, age{age}
{
}
string get_name() { return name; }
string get_job() { return job; }
int get_age() { return age; }
};
int main()
{
string name, job;
int age;
cout << "plaese enter name, job and age: \n";
cin >> name >> job >> age;
Person p{ name, job, age };
cout << "name = " << p.get_name() << ", job = " << p.get_job() << ", age = " << p.get_age() << endl;
}