struct anketa
{
int year;
char fio[64];
};
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
using namespace std;
struct Data
{
int value = 0;
string str;
};
ofstream& operator<<(ofstream& ofs, Data& d)
{
size_t sz = d.str.size();
ofs.write(reinterpret_cast<char*>(&d.value), sizeof(d.value));
ofs.write(reinterpret_cast<char*>(&sz), sizeof(sz));
ofs.write(d.str.c_str(), sz);
return ofs;
}
ifstream& operator>>(ifstream& ifs, Data& d)
{
ifs.read(reinterpret_cast<char*>(&d.value), sizeof(d.value));
size_t sz;
ifs.read(reinterpret_cast<char*>(&sz), sizeof(sz));
d.str.resize(sz);
ifs.read(reinterpret_cast<char*>(&*d.str.begin()), sz);
return ifs;
}
int main()
{
Data d = {42, "John Doe"};
ofstream ofs("D:\\file.bin", ios_base::binary);
ofs << d;
ofs.close();
Data d2;
ifstream ifs("D:\\file.bin", ios_base::binary);
ifs >> d2;
assert(d.value == d2.value && d.str == d2.str);
cin.get();
}
«Входите через узкие ворота, потому что широка и просторна дорога, ведущая в погибель, и многие идут ею, тогда как узки ворота и тесна дорога, ведущая в жизнь, и немногие находят ее» (Матфея 7:13, 14).)
как увязать degrees и координаты точек
Встань и иди.
С помощью
https://cppinsights.io/about.html