Advertisement
Pata15

Načítání ze souboru

Dec 16th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. /**
  2.  * @brief Nacte polozky ze zadaneho souboru
  3.  *
  4.  * @param string nazev souboru
  5.  * @param vector<sporttracker_item>* databaze polozek
  6.  *
  7.  * @return 0 - chyba, 1 - ok
  8.  *
  9.  * Funkce provadi nacteni udaju ze souboru csv
  10.  */
  11. int load_items(string db_filerok, vector<sporttracker_item>* ei)
  12. {
  13.     fstream db;
  14.  
  15.     //otevreni souboru
  16.     db.open(db_filerok.c_str(), fstream::in);
  17.  
  18.     if (!db.is_open())
  19.         return 0;
  20.  
  21.  
  22.     char buff[255];
  23.     sporttracker_item tmp_ei;
  24.  
  25.     while (db.good())
  26.     {
  27.         db.getline(buff, LINE_SIZE);
  28.  
  29.         if (db.good())
  30.         {
  31.             string line = string(buff);
  32.  
  33.             if (parse_item(line, &tmp_ei))
  34.             {
  35.                 ei->push_back(tmp_ei);
  36.             }
  37.  
  38.         }
  39.  
  40.     }
  41.     return 1;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement