Можно вот так.
#include
#include
using namespace std;
static int input(istream& inp, const char* prompt) {
cout << prompt;
int value;
inp >> value;
inp.ignore(0x1000, '\n');
return value;
}
class Building {
public:
Building()
: year(0) {}
Building(const int year, const string& type)
: year(year), type(type) {}
private:
int year;
string type;
static friend istream& operator>>(istream& inp, Building& bld) {
bld.year = input(inp, "Год: ");
cout << "Тип строения: ";
getline(inp, bld.type);
return inp;
}
static friend ostream& operator<<(ostream& out, const Building& bld) {
return out << bld.year << ' ' << bld.type;
}
};
int main() {
system("chcp 1251 > nul");
Building home;
cin >> home;
cout << home << '\n';
system("pause > nul");
}
#include <string>
using namespace std;
class Building {
private:
int year;
string type;
public:
Building(int y, string t) {
year = y;
type = t;
}
void get_info() {
cout << year << type << endl;
}
};
int main() {
setlocale(LC_ALL, "RU");
Building school(22, "Дом");
school.get_info();
return 0;
}