Advertisement
Alan468

event v3 c++

Apr 18th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 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 , cTag;
  37.     string sName, sDescription;
  38.  
  39.     char buff[100];
  40.     while (!File.eof())// określa liczbę linii do wczytania
  41.     {
  42.         File.getline(buff, 99);
  43.         iElements++;
  44.     }
  45.     iElements /= 3;
  46.     eMain_tab = new Event[iElements];
  47.  
  48.     File.clear();
  49.     File.seekg(0, ios::beg);
  50.  
  51.  
  52.     for (int i = 0; i < iElements; i++) { // Wypełnianie pól tablicy struktuy
  53.  
  54.                                           //File >> sName;
  55.                                           //File >> sDescription;
  56.  
  57.         getline(File, sName);
  58.         getline(File, sDescription);
  59.  
  60.         File >> iDay;
  61.         File >> iMonth;
  62.         File >> iYear;
  63.         File >> iHour;
  64.         File >> iMinutes;
  65.         File >> cTag;
  66.         File >> iPrioryty;
  67.  
  68.         eMain_tab[i].setName(sName);
  69.         eMain_tab[i].setDescription(sDescription);
  70.  
  71.         eMain_tab[i].setDay(iDay);
  72.         eMain_tab[i].setMonth(iMonth);
  73.         eMain_tab[i].setYear(iYear);
  74.         eMain_tab[i].setHour(iHour);
  75.         eMain_tab[i].setMinute(iMinutes);
  76.         eMain_tab[i].setTag(cTag);
  77.         eMain_tab[i].setPriority(iPrioryty);
  78.  
  79.         getline(File, sName);
  80.  
  81.         cout << "Name: " << eMain_tab[i].getName() << endl <<
  82.             "Desc: " << eMain_tab[i].getDescription() << endl <<
  83.             "Day: " << eMain_tab[i].getDay() << endl <<
  84.             "Month: " << eMain_tab[i].getMonth() << endl <<
  85.             "Year: " << eMain_tab[i].getYear() << endl <<
  86.             "Hours: " << eMain_tab[i].getHour() << endl <<
  87.             "Min: " << eMain_tab[i].getMinute() << endl <<
  88.             "Tag: " << eMain_tab[i].getTag() << endl <<
  89.             "Pri: " << eMain_tab[i].getPriority() << endl << endl;
  90.  
  91.     }
  92.     File.close();
  93.  
  94.     return eMain_tab;
  95. }
  96.  
  97.  
  98. int main() {
  99.  
  100.     const char* plikZdamymi = "ReadMe.txt";
  101.     File_Guardian Nowy;
  102.     Nowy.Read_File(plikZdamymi);
  103.     _getch();
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement