Advertisement
Alan468

Eventy v2 c++

Apr 18th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 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.     iElements /= 3;
  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.  
  55.                                           //File >> sName;
  56.                                           //File >> sDescription;
  57.  
  58.         getline(File, sName);
  59.         getline(File, sDescription);
  60.  
  61.         File >> iDay;
  62.         File >> iMonth;
  63.         File >> iYear;
  64.         File >> iHour;
  65.         File >> iMinutes;
  66.         File >> cTag;
  67.         File >> iPrioryty;
  68.  
  69.         eMain_tab[i].setName(sName);
  70.         eMain_tab[i].setDescription(sDescription);
  71.  
  72.         eMain_tab[i].setDay(iDay);
  73.         eMain_tab[i].setMonth(iMonth);
  74.         eMain_tab[i].setYear(iYear);
  75.         eMain_tab[i].setHour(iHour);
  76.         eMain_tab[i].setMinute(iMinutes);
  77.         eMain_tab[i].setTag(cTag);
  78.         eMain_tab[i].setPriority(iPrioryty);
  79.  
  80.         cout << "Name: " << eMain_tab[i].getName() << endl <<
  81.             "Desc: " << eMain_tab[i].getDescription() << endl <<
  82.             "Day: " << eMain_tab[i].getDay() << endl <<
  83.             "Month: " << eMain_tab[i].getMonth() << endl <<
  84.             "Year: " << eMain_tab[i].getYear() << endl <<
  85.             "Hours: " << eMain_tab[i].getHour() << endl <<
  86.             "Min: " << eMain_tab[i].getMinute() << endl <<
  87.             "Tag: " << eMain_tab[i].getTag() << endl <<
  88.             "Pri: " << eMain_tab[i].getPriority() << endl << endl;
  89.  
  90.     }
  91.     File.close();
  92.  
  93.     return eMain_tab;
  94. }
  95.  
  96.  
  97. int main() {
  98.  
  99.     const char* plikZdamymi = "ReadMe.txt";
  100.     File_Guardian Nowy;
  101.     Nowy.Read_File(plikZdamymi);
  102.     _getch();
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement