Если оператор перегружен для класса C++, как я могу использовать вместо него оператор по умолчанию?
Имеется уже созданий файл с данными. Перегрузил операторы чтения(чтение с фейла) и вывода(вывод на экран и в другой созданный файл). Такова задача: нужно сделать вывод на дисплей и файл информации о людях, чей день, месяц и год рождения были введены с клавиатуры, ориентируясь на информацию, которая была выведена через перегруженный оператор. Но вводить обычный std::cin я не могу.
Код прилагается:
#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>
using namespace std;
class Organizer
{
const int size = 10;
string name, surname, patronymic;
string number;
int day, month, year;
int* data = new int[size];
public:
~Organizer()
{
//cout << "\nThe destructor worked!" << endl << this << endl;
delete[] data;
}
void print_data()
{
cout << "\n\tData of birth: " << day << "/" << month << "/" << year << endl;
}
friend ifstream& operator >>(ifstream& t, Organizer& o);
friend ostream& operator <<(ostream& t, Organizer& o);
friend ofstream& operator <<(ofstream& t, Organizer& o);
};
ifstream& operator >>(ifstream& t, Organizer& o)
{
t >> o.name;
t >> o.surname;
t >> o.patronymic;
t >> o.number;
t >> o.day;
t >> o.month;
t >> o.year;
o.data[0] = o.day;
o.data[1] = o.month;
o.data[2] = o.year;
return t;
}
ostream& operator <<(ostream& t, Organizer& o)
{
t << "Person: " << o.name << " " << o.surname[0] << "." << o.patronymic[0] << "." << endl;
t << "\tNumber: +38" << o.number << "\n\t\tData: " << o.data[0] << "/" << o.data[1] << "/" << o.data[2] << endl;
return t;
}
ofstream& operator <<(ofstream& t, Organizer& o)
{
t << "Person: " << o.name << " " << o.surname[0] << "." << o.patronymic[0] << "." << endl;
t << "\tNumber: +38" << o.number << "\n\t\tData: " << o.data[0] << "/" << o.data[1] << "/" << o.data[2] << endl;
return t;
}
int main(void)
{
ofstream infoFile_out("people_out.txt");
if (!infoFile_out)
{
cout << "people_out.txt";
_getch();
return 0;
}
ifstream infoFile("people.txt");
if (infoFile.is_open()) {
while (!infoFile.eof())
{
Organizer o;
infoFile >> o;
o.print_data();
infoFile_out << o;
}
//cin << something;
}
else
{
cout << "Can't open file people.txt";
_getch();
return 0;
}
infoFile.close();
infoFile_out.close();
_getch();
return 0;
}