Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <tchar.h>
- #include <conio.h>
- #include <string>
- #include <fstream>
- #include <iostream>
- #include "Event.h"
- using namespace std;
- class File_Guardian {
- Event *eMain_tab;
- int iElements = 0;
- public:
- File_Guardian();
- Event* Read_File(const char* File_name);
- };
- File_Guardian::File_Guardian() {
- iElements = 0;
- eMain_tab = NULL;
- }
- Event *File_Guardian::Read_File(const char* File_name) { // Otwiera plik,tworzy oraz wypełnia Tablice
- ifstream File;
- File.open(File_name);
- //FILE *File = fopen(File_name, "r");
- if (!File.is_open()) {
- printf("Blad otwarcia pliku z danymi");
- _getch();
- }
- int iDay, iMonth, iYear, iHour, iMinutes, iPrioryty;
- string sName, sDescription;
- char cTag;
- char buff[100];
- while (!File.eof())// określa liczbę linii do wczytania
- {
- File.getline(buff, 99);
- iElements++;
- }
- iElements /= 3;
- eMain_tab = new Event[iElements];
- File.clear();
- File.seekg(0, ios::beg);
- for (int i = 0; i < iElements; i++) { // Wypełnianie pól tablicy struktuy
- //File >> sName;
- //File >> sDescription;
- getline(File, sName);
- getline(File, sDescription);
- File >> iDay;
- File >> iMonth;
- File >> iYear;
- File >> iHour;
- File >> iMinutes;
- File >> cTag;
- File >> iPrioryty;
- eMain_tab[i].setName(sName);
- eMain_tab[i].setDescription(sDescription);
- eMain_tab[i].setDay(iDay);
- eMain_tab[i].setMonth(iMonth);
- eMain_tab[i].setYear(iYear);
- eMain_tab[i].setHour(iHour);
- eMain_tab[i].setMinute(iMinutes);
- eMain_tab[i].setTag(cTag);
- eMain_tab[i].setPriority(iPrioryty);
- cout << "Name: " << eMain_tab[i].getName() << endl <<
- "Desc: " << eMain_tab[i].getDescription() << endl <<
- "Day: " << eMain_tab[i].getDay() << endl <<
- "Month: " << eMain_tab[i].getMonth() << endl <<
- "Year: " << eMain_tab[i].getYear() << endl <<
- "Hours: " << eMain_tab[i].getHour() << endl <<
- "Min: " << eMain_tab[i].getMinute() << endl <<
- "Tag: " << eMain_tab[i].getTag() << endl <<
- "Pri: " << eMain_tab[i].getPriority() << endl << endl;
- }
- File.close();
- return eMain_tab;
- }
- int main() {
- const char* plikZdamymi = "ReadMe.txt";
- File_Guardian Nowy;
- Nowy.Read_File(plikZdamymi);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement