Advertisement
Alan468

Untitled

Apr 18th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <tchar.h>
  4. #include <conio.h>
  5. #include <string>
  6. #include <fstream>
  7. #include <iostream>
  8.  
  9. #include "Event.h"
  10. using namespace std;
  11. class File_Guardian {
  12.     Event *eMain_tab;
  13.     int iElements = 0;
  14. public:
  15.  
  16.     File_Guardian();
  17.     Event* Read_File(const char* File_name);
  18.  
  19. };
  20.  
  21. File_Guardian::File_Guardian() {
  22.     iElements = 0;
  23.     eMain_tab = NULL;
  24. }
  25.  
  26. Event *File_Guardian::Read_File(const char* File_name) { // Otwiera plik,tworzy oraz wypełnia Tablice
  27.  
  28.     ifstream File;
  29.     File.open(File_name);
  30.     //FILE *File = fopen(File_name, "r");
  31.     if (!File.is_open()) {
  32.         printf("Blad otwarcia pliku z danymi");
  33.         _getch();
  34.     }
  35.  
  36.     int  iDay, iMonth, iYear, iHour, iMinutes, iPrioryty;
  37.     string sName, sDescription;
  38.     char cTag;
  39.  
  40.     char buff[100];
  41.     while (!File.eof())// określa liczbę linii do wczytania
  42.     {
  43.         File.getline(buff, 99);
  44.         iElements++;
  45.     }
  46.  
  47.     eMain_tab = new Event[iElements];
  48.  
  49.     File.clear();
  50.     File.seekg(0, ios::beg);
  51.  
  52.  
  53.     for (int i = 0; i < iElements; i++) { // Wypełnianie pól tablicy struktuy
  54.         File >> sName;
  55.         File >> sDescription;
  56.         File >> iDay;
  57.         File >> iMonth;
  58.         File >> iYear;
  59.         File >> iHour;
  60.         File >> iMinutes;
  61.         File >> cTag;
  62.         File >> iPrioryty;
  63.  
  64.         eMain_tab[i].setName(sName);
  65.         eMain_tab[i].setDescription(sDescription);
  66.  
  67.         eMain_tab[i].setDay(iDay);
  68.         eMain_tab[i].setMonth(iMonth);
  69.         eMain_tab[i].setYear(iYear);
  70.         eMain_tab[i].setHour(iHour);
  71.         eMain_tab[i].setMinute(iMinutes);
  72.         eMain_tab[i].setTag(cTag);
  73.         eMain_tab[i].setPriority(iPrioryty);
  74.  
  75.         cout << "Name: " << eMain_tab[i].getName() << endl <<
  76.             "Desc: " << eMain_tab[i].getDescription() << endl <<
  77.             "Day: " << eMain_tab[i].getDay() << endl <<
  78.             "Month: " << eMain_tab[i].getMonth() << endl <<
  79.             "Year: " << eMain_tab[i].getYear() << endl <<
  80.             "Hours: " << eMain_tab[i].getHour() << endl <<
  81.             "Min: " << eMain_tab[i].getMinute() << endl <<
  82.             "Tag: " << eMain_tab[i].getTag() << endl <<
  83.             "Pri: " << eMain_tab[i].getPriority() << endl << endl;
  84.  
  85.     }
  86.     File.close();
  87.  
  88.     return eMain_tab;
  89. }
  90.  
  91.  
  92. int main() {
  93.  
  94.     const char* plikZdamymi = "ReadMe.txt";
  95.     File_Guardian Nowy;
  96.     Nowy.Read_File(plikZdamymi);
  97.     _getch();
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement