Страница 1 из 1

загрузка файла в структуру

Добавлено: 29 май 2010, 14:02
artemi
не могу загрузить фаил в структуру
вот мой код:

Код: Выделить всё

#include <iostream>
#include <iterator>
#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;



struct Perech
{int nomer;
string outpunkt;
string inpunkt;
int h,min;
int cost;
int mest;
       };



class vokzal
{
 private:
   std::vector<Perech> v;
   Perech *px;
   int n;

 public:
   vokzal(){n=0;px=NULL;}
  ~vokzal(){n=0;if(px!=NULL)delete[]px;}
   void newBD();
   void output();
   void outputFile();
   void inputfile();

  };

void vokzal: :o utputFile()  //сохранение БД в файл
{std: :o fstream fout;
 char file[20]; //переменная для названия файла
 int i; //рабочая переменная для подсчёта
 if (v.size() == 0){cout<<"Massiv pust\n";getch();return;}
 cout<<"Vvedite fail dlya sohraneniya: ";cin>>file;
 fout.open(file,ios: :o ut|ios::trunc);
 try{
 if(fout.fail()){cout<<file<<" Ne sozdan\n";getch();n=0;px=NULL;return;}
//запись БД в файл
 for( size_t i=0;i< v.size();i++)
    {fout.setf(ios::left);
 fout<<setw(6)<<v[i].nomer<<setw(12)<<v[i].outpunkt<<setw(11)<<v[i].inpunkt
 <<setw(3)<<v[i].h<<setw(4)<<v[i].min<<setw(17)<<v[i].mest<<setw(8)<<v[i].cost<<endl;
 }
 cout<<"Baza dannuih sohranena\n";getch();
}
 catch(...)

{
       cout<<"Error";
       getch();
        }
    }

void vokzal::newBD()
{
  int i;
  clrscr();
cout<<"Kolichestvo zapisey=";cin>>n;
 if(px!=NULL)delete[] px;
  px=new Perech[n];
 try{
  if(px==NULL){cout<<"Net pamyati\n";getch();n=0;return;}
  for(i=0;i<n;i++)
 {cout<<"Nomer avtobusa:";cin>>px[i].nomer;
  cout<<"Punkt otpravleniya: ";cin>>px[i].outpunkt;
  cout<<"Punkt naznacheniya: ";cin>>px[i].inpunkt;
  cout<<"Vremya otpravleniya: ";cin>>px[i].h>>px[i].min;
   cout<<"Stoimost bileta: ";cin>>px[i].cost;
  cout<<"Kolichestvo mest: ";cin>>px[i].mest;
  cout<<endl;
  v.push_back(px[i]);
 }

 cout<<"Baza dannuih sozdana"<<endl;getch();
 }
  catch(...)

{
       cout<<"Error";
       getch();
        }

}




void vokzal: :o utput(){
  if (v.size()==0){cout<<"    "<<"V baze dannuih net zapisey\n";getch();return;}
  clrscr();
 cout.setf(ios::left);
 cout<<endl<<"Baza dannuih 'Avtovokzal'\n"<<endl;
 cout<<"N"<<" "<<setw(6)<<"Nomer"<<setw(12)<<"Otpravlenie"<<setw(11)<<"Pribuitie"
 <<setw(7)<<"Vremya"<<setw(17)<<"kolichestvo mest"<<setw(8)<<"Stoimost"<<endl;
  for (size_t i = 0; i < v.size(); i++){
  {cout.setf(ios::left); i++;
 cout<<setw(3)<<i<<setw(6)<<v[i-1].nomer<<setw(12)<<v[i-1].outpunkt<<setw(11)<<v[i-1].inpunkt
  <<setw(1)<<v[i-1].h<<":"<<setw(3)<<v[i-1].min<<setw(17)<<v[i-1].mest<<setw(8)<<v[i-1].cost<<endl;
i--; }

 }
    getch();
  }




void vokzal::inputfile()  //ввод БД из файла
{
int i;      //рабочая переменная для подсчёта
 Perech t;  //рабочая переменная для подсчёта записей в файле
 char file[10]; //переменная для названия файла
 if(px!=NULL){delete[]px;n=0;px=NULL;}  //очистка рабочей области(массива)
 cout<<"Imya vhodnogo faila: ";cin>>file;
ifstream  fin;
 fin.open(file,ios::in|ios: :o ut);
  if(!fin.eof())
 do{fin>>t.nomer>>t.outpunkt>>t.inpunkt>>t.h>>t.min>>t.mest>>t.cost;
  n++;
   } while(fin.good()); //пока файл не закончился
n--;
  px=new Perech[n]; //выделение динамической памти
    //ввод массива задолжников из файла
for(i=0;i<n;i++)
 {fin>>px[i].nomer>>px[i].outpunkt>>px[i].inpunkt>>px[i].h>>px[i].min>>px[i].mest>>px[i].cost;
  v.push_back(px[i]);}
  fin.close();
}





int main(){
 vokzal a;
 char g;
 do{
    clrscr();
     cout<<"          "<<"Meny kassy avtovokzal\n";
     cout<<"        "<<"1 - New raspisanie avtobusov\n";
     cout<<"        "<<"2 - Save raspisanie v fail\n";
     cout<<"        "<<"3 - load raspisanie iz faila\n";
     cout<<"        "<<"4 - Prosmotr raspisaniy\n";
     cout<<"        "<<"E - Exit \n";
     cout<<"   "<<"Viberete punkt menu\n";
     cin>>g;
  switch(g){
  case '1':a.newBD();break;
    case '2':a.outputFile();break;
  case '3':a.inputfile();break;
    case '4':a.output();break;
 }
 }while(g!='E');
 return 0;
 }





































Re: загрузка файла в структуру

Добавлено: 02 июн 2010, 08:37
two0426
Nurturing nature has been adjusted to the fourth floor. It allows your therapeutic effects of healing spells to increase, which is equal to thirty five to seventy percent of the agile value, and you suffered therapeutic effect in cheetah form improves by ten to twenty percent. Bester attack no longer provides attack strength in WOW.
Your ultimate skill can provide each combo points by
wow power leveling wow gold louis vuitton handbags wedding dresses aion power leveling rolex Watches wow power leveling take it as a wejsklds truism that MMOs can be can be reduced to a series of grinds -- ones that we consensually undergo because the rewards are somehow worth it
If you look at WoW, the nature of the grind may have evolved a little bit, but it hasn't really changed. At first,we grinded instances wow gold and raids for boss drops. Then the honor system came along, and we began grinding ranks. And when the honor system changed, we did it for
points -- and often, no real effort was required on our part (forward to 5:27).But the grind truly came louis vuitton handbags into its own once The Burning Crusade launched. Badges of Honor -- which have become more and more liberally dispensed as the expansion
was iterated on -- made it so that we had an incentive to run even those dungeons that we liked least. They did away with the notion of the wedding dresses rewardless instance run; regardless of whether or not you got a bauble from a boss, the handful of badges you'd walk away with would net
you something useful. Eventually.We've gotten used to incremental aion power leveling rewards for time spent. There's a lot to say about this, but that's outside of the scope of this piece. Blizzard too has gotten much better
at building systems into WoW that work around our willingness to be incentivized in this way.Effort Sink rolex Watches Heirloom items. Following yesterday's beta update, a player found these fascinating items on a badge vendor, which prompted a response from xll
seven to twenty percent of chance to make your next cast time less than ten seconds of the natural spells become instant. Primitive rage can cause a deadly blow to the target when you are bear and dire bear form. There is also fifty to one hundred percent of chance to receive an additional five points of rage. In cheetah form, you could have fifty to one hundred percent of chance to re-obtain an additional combo point after increased that of skills to cause a deadly blow.
In the fifth floor, brutal collision capacities have been reduced. It allows your stun duration of blow and the surprise attack for zero point five to one second, the cooling time of blow reduces five to ten seconds. Wild Heart was adjusted to the fifth floor. Your intellect rises by four to twenty percent in WOW. In addition, in bear or dire bear form, your endurance can be improved two to ten percent. In cheetah form, your attack power can be increased by two to ten percent.
Survival instinct was adjusted from the third layer to the fifth floor. After started it, the skill makes your vitality limit temporarily increased by thirty percent and last twenty seconds in bear, cheetah or dire bear form. After the effect of lifting, these vitalities will be deducted.
Survival of the fittest no longer provides properties in the sixth floor. It makes crit chance suffered by melee attack reduced by two to six percent. It also increases your armor value by eleven to thirty three percent from leather and cloth equipments in dire bear and bear form. Those above changes players can experience when they buy WOW gold to play the game. I believe that we may all hope to see them xll