Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- void siralama(struct al* a);
- void gir(struct al* a);
- void yaz(struct al* a);
- struct al
- {
- string country;
- string city;
- };
- void gir(struct al* a) {
- for (int i = 0; i < 5; i++) {
- cout << "country" << i + 1 << ":";
- cin >> a[i].country;
- cout << "city" << i + 1 << ":";
- cin >> a[i].city;
- }
- }
- void yaz(struct al* a) {
- ofstream yap("myfile.txt", ios::binary);
- for (int i = 0; i < 5; i++) {
- yap << a[i].country << "-" << a[i].city << endl;
- }
- yap.close();
- }
- void siralama(struct al* a) {
- ofstream ayir("deneme2.txt", ios::binary);
- for (int i = 0; i < 5; i++) {
- if ((*(a + i)).country == "italy") {
- ayir << a[i].country << "-" << a[i].city << endl;
- }
- }
- ayir.close();
- }
- int main()
- {
- ifstream fromfile;
- struct al a[100];
- string satir = " ";
- char b = 'n';
- do {
- cout << "select a number:" << endl;
- cout << "1-data entry:" << endl << "2-print and reading the entered data to a file:" << endl << "3:Sorting data:" << endl << "4:delete data:" << endl;
- int task;
- cin >> task;
- cin.get();
- switch (task)
- {
- case 1: {
- gir(&a[0]);
- break;
- }
- case 2: {
- ofstream yap("myfile.txt", ios::binary);
- yaz(&a[0]);
- fromfile.open("myfile.txt", ios::binary);
- while (getline(fromfile, satir)) {
- cout << satir << endl;
- }
- fromfile.close();
- yap.close();
- break;
- }
- case 3: {
- ofstream ayir("deneme2.txt",ios::binary);
- siralama(&a[0]);
- ifstream bir("deneme2.txt", ios::binary);
- while (getline(bir, satir)) {
- cout << satir << endl;
- }
- bir.close();
- ayir.close();
- break;
- }
- case 4: {
- int sonuc = remove("deneme2.txt");
- if (sonuc == 0) {
- cout << "file deleted!!" << endl;;
- }
- break;
- }
- default:
- {
- cout << "Incorect task number" << "\n";
- break;
- }
- }
- cout << "If you want to exit, input y" << endl;
- cin >> b;
- cin.ignore(256, '\n');
- } while (b != 'y'); {
- cout << "exit!!";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement