Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Для новичков > Чтение из файла


Автор: loadcpp 7.2.2012, 18:07
Есть программа которая записывает структуру в файл:

Код

#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
 
using namespace std;
 
struct sportTeam {
        string  name;
        string cityname;
        int  players;
    int  points;} ;
 
 
int main()
{   int quan, n;
        sportTeam *team;
        cout << "Input a quantity of teams\t";
        cin >> quan;
        team = new sportTeam[quan];
        //---------------------------------------------------------------
        //      ПИШЕМ В ФАЙЛ
        //----------------------------------------------------------
        ofstream  ourfile;
        ourfile.open("fileOne2.txt",ios::app);
        for(int i = 0 ;i < quan;i++){
        cout << "Input a name of  " << (i+1)<<"  team\t";
        cin >> team[i].name;
        ourfile <<  (i+1) << " team's name : "  << team[i].name << '\n';
        cout << "Name of city\t";
        cin >> team[i].cityname;
        ourfile <<  "Name of city : "  << team[i].name << '\n';
        cout << "Input a quantity of players : ";
        cin >> team[i].players;
        ourfile <<  "Quantity of players : "  << team[i].players << '\n';
        cout << "Input a  points : ";
        cin >> team[i].points;
        ourfile <<  "Quantity of points : "  << team[i].points << '\n';}
        
        ourfile.close();
        cout << endl;

        cout << "Kolichestvo ochek: "; 
        cin >> n;

        //---------------------------------------------------------------
        //      ЧИТАЕМ  ФАЙЛ 
        //----------------------------------------------------------
        string mystring;
        ifstream  ourfile2;
        ourfile2.open("fileOne2.txt");
        
        while(!ourfile2.fail()){
                getline(ourfile2,mystring);
                cout << mystring << endl;}
        ourfile2.close();
        delete[] team;
        system("pause");
}


В файл записываться структура:

Спортивная команда":
- название;
- город;
- количество игроков;
- количество очек. 

Нужно удалить из файла команды, у которой очек меньше чем задаёт пользователь.

1) Записать в файл команды [готово]
2) Спросить максимальное количество очек [готово]
3) Удалить команды у которых меньше очек чем задал пользователь [проблема]

Автор: newbee 7.2.2012, 19:38
Загрузи все команды из файла, отфильтруй и запиши обратно.

Автор: loadcpp 7.2.2012, 20:34
newbee, спасибо за совет, получилось. Позже выложу сурс.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)