Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "json.hpp"
- #include <fstream>
- #include "iostream"
- #include "iconvlite.h"
- using json = nlohmann::json;
- using namespace std;
- class My_Class
- {
- public:
- int number;
- std::string name;
- double masive[3];
- public:
- My_Class() {};
- My_Class(int n) : number(n)
- {
- std::cout << "Enter the string for object\n";
- std :: string str_obj;
- std::cin >> str_obj;
- string str_utf = cp2utf(str_obj);
- name = str_utf;
- std::cout << "Enter the number for massive\n";
- for (int i = 0; i < 3; i++)
- {
- std::cin >> masive[i];
- }
- }
- My_Class(int n, std::string m) : number(n), name(m)
- {
- std::cout << "Enter the number for massive\n";
- for (int i = 0; i < 3; i++)
- {
- std::cin >> masive[i];
- }
- }
- void write_json()
- {
- nlohmann::json j;
- j["number"] = number;
- j["name"] = name;
- j["masive"] = masive;
- std::fstream file;
- file.open("data.json", std::ios::app);
- file << j;
- std::cout << "Файл записан\n";
- file.close();
- }
- void read_json()
- {
- nlohmann::json j;
- json j_array = json::array();
- std::fstream file;
- file.open("data2.json");
- file >> j_array;
- file.close();
- json::iterator it = j_array.begin();
- for (it; it != j_array.end(); it++) {
- json j;
- j = *it;
- name = utf2cp(j["name"].dump());
- cout << name << endl;
- }
- }
- };
- int main()
- {
- system("chcp 1251");
- setlocale(LC_ALL, "Russian");
- My_Class m;
- m.read_json();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement