Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef DATABASE_HPP_INCLUDED
- #define DATABASE_HPP_INCLUDED
- #include <iostream>
- #include <vector>
- #include <json/json.h>
- #include <fstream>
- using namespace std;
- class Database {
- public:
- void loadFromFile (const string& fname) {
- Json::Value root;
- ifstream file (fname);
- if (!file.is_open())
- cout << "shit happens\n";
- file >> root;
- Json::Value jBooks = root["books"];
- if (!jBooks.isNull()) {
- for (int i = 0; i < jBooks.size(); i++) {
- Book b;
- b.author = jBooks[i]["author"].asString();
- books.push_back (b);
- }
- }
- }
- private:
- vector <Book> books;
- };
- #endif // DATABASE_HPP_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement