Created
December 12, 2016 19:35
-
-
Save Zulcom/d8af9db9eb114560b6e2111d3847647a to your computer and use it in GitHub Desktop.
Yuri help comission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <clocale> | |
#include <iostream> | |
#include <fstream> | |
#include <conio.h> | |
#include <string> | |
#include <windows.h> | |
using namespace std; | |
struct turist | |
{ | |
string surname; | |
int age; | |
string city; | |
string education; | |
turist *llink; | |
turist *rlink; | |
}; | |
int main() | |
{ | |
system("chcp 1251"); | |
turist *k, *nogi, *golova, *q; | |
string file,gorod; | |
ifstream txt("Ishod.txt"); | |
cout << "Содержимое текстового файла:" << endl; | |
k = new turist; | |
txt >> k->surname >> k->age >> k->city>> k->education; | |
cout << k->surname << " " << k->age << " "<< k->city << " " << k->education << endl; | |
k->rlink = NULL; | |
k->llink = NULL; | |
golova = k; | |
q = k; | |
while(!txt.eof()) | |
{ | |
k = new turist; | |
txt >> k->surname; | |
txt >> k->age; | |
txt >> k->city; | |
txt >> k->education; | |
cout << k->surname << " " << k->age << " " | |
<< k->city << " " << k->education << endl; | |
k->rlink = q; | |
q->llink = k; | |
q = k; | |
} | |
nogi = q; | |
q->llink = NULL; | |
k = golova; | |
cout << "Введите название города: "; | |
cin >> gorod; | |
cout << endl << "Введите название создаваемого файла: "; | |
cin >> file; | |
ofstream bin_write(file + ".txt", ios::binary); | |
int counter = 0; // выводим с текстового файла столько же, сколько и вводим, считаем ввод | |
while(k != NULL) | |
{ | |
if(k->city == gorod) | |
{ | |
bin_write.write((char*) k, sizeof(turist)); | |
counter++; | |
} | |
k = k->llink; | |
} | |
bin_write.close(); | |
ifstream bin_read(file + ".txt", ios::binary); | |
cout << endl << "Содержимое двоичного файла:" << endl; | |
q = new turist; | |
for(int i = 0; i < counter; i++) // и выводим ровно столько строк, сколько ввели | |
{ | |
bin_read.read((char*) q, sizeof(turist)); | |
cout << q->surname << " " << q->age << " " | |
<< q->city << " " << q->education << endl; | |
} | |
bin_read.close(); | |
_getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment