#pragma warning(disable:4996)
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
struct Data {
int year;
int mounth;
int day;
};
struct AutoBase {
string Name;
Data Release;
Data SaleRelease;
};
void input();
void output(string);
AutoBase Divide(AutoBase, string, bool);
int main()
{
input();
cout << "\nList of cars";
output("AutoBase.txt");
}
void input() {
ofstream In("AutoBase.txt", ios::binary);
char k = '+';
AutoBase a;
string Read;
while (k == '+') {
cout << "Enter name of car: "; getline(cin, a.Name);
cout << "Enter Release Date with a point '10.10.2010': "; getline(cin, Read);
a = Divide(a, Read, 0);
cout << "Enter Sale Release Date with a point '10.10.2010': "; getline(cin, Read);
a = Divide(a, Read, 1);
cout << "\nEnter '+' in case you want to contnue: "; cin >> k;
In.write((char*)&a, sizeof(AutoBase));
cin.ignore();
}
In.close();
}
AutoBase Divide(AutoBase a, string Read, bool b) {
int pos1 = Read.find('.');
int pos2 = Read.rfind('.');
if (!b) {
a.Release.day = stoi(Read.substr(0, pos1));
a.Release.mounth = stoi(Read.substr(pos1 + 1, pos2));
a.Release.year = stoi(Read.substr(pos2 + 1));
}
else {
a.SaleRelease.day = stoi(Read.substr(0, pos1));
a.SaleRelease.mounth = stoi(Read.substr(pos1 + 1, pos2));
a.SaleRelease.year = stoi(Read.substr(pos2 + 1));
}
return a;
}
void output(string name) {
ifstream Out(name, ios::binary);
AutoBase a;
while (Out.read((char*)&a, sizeof(AutoBase))) {
cout << endl << "Name: " << a.Name << " Release date: " << a.Release.day << "." << a.Release.mounth << "." << a.Release.year << " Slae Release Date: " << a.SaleRelease.day << "." << a.SaleRelease.mounth << "." << a.SaleRelease.year;
}
Out.close();
}
После вывода содержимого файла в консольку выдает ошибку.