152 lines
3.6 KiB
C++
152 lines
3.6 KiB
C++
//#include <iostream>
|
|
//#include <fstream>
|
|
//#define N 7
|
|
//using namespace std;
|
|
//const int sz = 25;
|
|
//struct Marsh {
|
|
// char nomer[7]
|
|
// char marshBegin[sz];//Èìÿ ïî÷àòêîâî¿ çóïèíêè
|
|
// char marshEnd[sz];//Èìÿ îñòàííÿé çóïèíêè
|
|
// int count;//ê³ëüê³ñòü çóïèíîê
|
|
// int tm;//÷àñ ì³æ çóï³íêàìè
|
|
// void init();
|
|
// void show();
|
|
//};
|
|
//
|
|
//int main()
|
|
//{
|
|
// Marsh marsh;
|
|
// int vUser;
|
|
// ofstream fout;
|
|
// fout.open(".\\Data\\info.dat", ios::binary);
|
|
// if (!fout.is_open()) {
|
|
// cerr << "Error: open file(out)\n";
|
|
// system("pause");
|
|
// return 1;
|
|
// }
|
|
//
|
|
// do {
|
|
// marsh.init();
|
|
// fout.write(reinterpret_cast<char*>(&marsh), sizeof(Marsh));
|
|
// } while (vUser != 0);
|
|
// fout.close();
|
|
// ifstream fin;
|
|
// fin.open(".\\Data\\info.dat", ios::binary);
|
|
// if (!fin.is_open()) {
|
|
// cerr << "Error: open file(in)\n";
|
|
// system("pause");
|
|
// return 1;
|
|
// }
|
|
// fin.seekg(0, ios::end);
|
|
// int size = (int)fin.tellg();
|
|
// int n = size/sizeof(M)
|
|
//}
|
|
//void Marsh::init() {
|
|
// cout << "Input nomer: ";
|
|
// cin.getline(nomer, N);
|
|
// cout << "Begin: ";
|
|
// cin.get(marshBegin, sz);
|
|
// cout << "End: ";
|
|
// cin.get(marshEnd, sz);
|
|
// cout << " count: ";
|
|
// cin >> tm;
|
|
// cin.ignore();
|
|
//}
|
|
//void Marsh::show() {
|
|
// cout << "Nomer: " << nomer
|
|
// << "\nBegin: " << marshBegin
|
|
// << "\nEnd: " << marshEnd
|
|
// << "\n count: " << count + 2
|
|
// << "\n time: " << fm << endl;
|
|
//}
|
|
//
|
|
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#define N 7
|
|
using namespace std;
|
|
const int sz = 25;
|
|
|
|
struct Marsh {
|
|
char nomer[7];
|
|
char marshBegin[sz];
|
|
char marshEnd[sz];
|
|
int count;
|
|
int tm;//time
|
|
void init();
|
|
void show();
|
|
};
|
|
|
|
void show(Marsh* p, int n) {
|
|
for (int i = 0; i < n; ++i)
|
|
p[i].show();
|
|
}
|
|
|
|
int main()
|
|
{
|
|
//".\\resFile\\infoMars.dat"
|
|
// Marsh marsh;
|
|
Marsh* pMarsh = new Marsh;
|
|
int vUser;
|
|
ofstream fout;
|
|
fout.open(".\\Data\\info.dat", ios::binary);//ios::out
|
|
if (!fout.is_open()) {
|
|
cerr << "Error: open file(out)\n";
|
|
system("pause");
|
|
return 1;
|
|
}
|
|
|
|
do {
|
|
/*marsh.init();
|
|
fout.write(reinterpret_cast<char*>(&marsh), sizeof(Marsh));*/
|
|
pMarsh->init();
|
|
fout.write(reinterpret_cast<char*>(pMarsh), sizeof(Marsh));
|
|
cout << "Create Marsh?(1(Yes)/0(No) ";
|
|
cin >> vUser;
|
|
cin.ignore();
|
|
} while (vUser != 0);
|
|
delete pMarsh;
|
|
fout.close();
|
|
ifstream fIn;
|
|
fIn.open(".\\Data\\info.dat", ios::binary);//ios::out
|
|
if (!fIn.is_open()) {
|
|
cerr << "Error: open file(out)\n";
|
|
system("pause");
|
|
return 1;
|
|
}
|
|
fIn.seekg(0, ios::end);
|
|
int size = (int)fIn.tellg();
|
|
int n = size / sizeof(Marsh);//n!=0
|
|
pMarsh = new Marsh[n];
|
|
fIn.seekg(0);
|
|
for (int i = 0; i < n; ++i) {
|
|
fIn.read(reinterpret_cast<char*>(pMarsh + i), sizeof(Marsh));
|
|
}
|
|
fIn.close();
|
|
show(pMarsh, n);
|
|
delete[] pMarsh;
|
|
system("pause");
|
|
}
|
|
void Marsh::init() {
|
|
cout << "Input nomer: ";
|
|
cin.getline(nomer, N);
|
|
cout << "Begin: ";
|
|
cin.getline(marshBegin, sz);
|
|
cout << "End: ";
|
|
cin.getline(marshEnd, sz);
|
|
cout << " count: ";
|
|
cin >> count;
|
|
cout << "midle time: ";
|
|
cin >> tm;
|
|
cin.ignore();
|
|
}
|
|
void Marsh::show() {
|
|
cout << "Nomer: " << nomer
|
|
<< "\nBegin: " << marshBegin
|
|
<< "\n End: " << marshEnd
|
|
<< "\n count: " << count + 2
|
|
<< "\n time: " << tm << endl;
|
|
}
|
|
|
|
|