Другие языки программирования и технологии

С++ работа с файлами, как достать отдельно слова из файла

Заполнить структуру данными из файла, данные вида
"Имя Фамилия 10.10.2020 89"
Дату рождения отдельно сохранить как массив 3 чисел
89 - оклад
#include <iostream>
#include <string>
#include <sstream>
#include <tuple>
#include <regex>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
struct Box {
Box() : day(0), month(0), year(0), salary(.0) {}
int day;
int month;
int year;
double salary;
string name;
string surname;
string tostring()const {
auto rub = static_cast<unsigned>(salary);
auto kop = static_cast<unsigned>(round((salary - rub) * 100));
auto str = surname + ' ' + name + " - " + to_string(day) + pos[month] + to_string(year) + " г. р. = " + to_string(rub) + '.';
if (kop < 10) str += '0';
str += to_string(kop) + " руб.";
return str;
}
friend ostream& operator<<(ostream& out, const Box& box) {
out << box.tostring();
return out;
}
friend bool operator<(const Box& a, const Box& b) {
if (a.surname < b.surname) return true;
if (a.surname == b.surname) {
if (a.name < b.name) return true;
if (a.name == b.name) {
if (a.year < b.year) return true;
if (a.year == b.year) {
if (a.month < b.month) return true;
if (a.month == b.month) return a.day <= b.day;
}
}
}
return false;
}
static string pos[13];
};
string Box::pos[13] = { "", " января ", " февраля ", " марта ", " апреля ", " мая ", " июня ", " июля ", " августа ", " сентября ", " октября ", " ноября ", " декабря " };
tuple<int, int, int> split(const string& date) {
auto tmp = date;
tmp = regex_replace(tmp, regex("[.-/]"), " ");
istringstream iss(tmp);
int d, m, y;
iss >> d >> m >> y;
return { d, m, y };
}
Box parse(const string& record) {
Box box;
string date;
istringstream iss(record);
iss >> box.name >> box.surname >> date >> box.salary;
auto [day, month, year] = split(date);
box.day = day;
box.month = month;
box.year = year;
return box;
}
int main() {
// Для файла данных в кодировке Windows 1251
system("chcp 1251 > nul");
// Сохранить строки данных из файла в вектор
vector<string> records{
"Константин Цзю 19.09.1969 340680.99",
"Фёдор Емельяненко 28.09.1976 750000.10",
"Хабиб Нурмагомедов 20.09.1988 960000.09",
};
vector<Box> table;
for (const auto& record : records) table.push_back(parse(record));
sort(table.begin(), table.end());
copy(table.begin(), table.end(), ostream_iterator<Box>(cout, "\n"));
cin.get();
}
Бутусов Михаил
Бутусов Михаил
87 740
Лучший ответ
Примерно так

cin>>N>>F>>a[0]>>temp>>a[1]>>temp>>a[2]>>O;

https://ideone.com/qHCFHS
Отдельно? Если это не файл структуры базы данных, то только считывая весь файл или известными порциями...