Загрузить файлы в «/»
This commit is contained in:
151
Home_Task1.cpp
Normal file
151
Home_Task1.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
//#include <iostream>
|
||||
//#include <fstream>
|
||||
//#define N 7
|
||||
//using namespace std;
|
||||
//const int sz = 25;
|
||||
//struct Marsh {
|
||||
// char nomer[7]
|
||||
// char marshBegin[sz];//<2F><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// char marshEnd[sz];//<2F><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// int count;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// int tm;//<2F><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user