Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <filesystem>
- #include "nlohmann/json.hpp"
- int main() {
- // Default file content: {"This are big":["Whale", "Cat"]}
- std::ifstream input("D://input.txt");
- nlohmann::json j;
- input >> j;
- input.close();
- auto question = j.begin();
- char resp;
- while (true) {
- std::cout << question.key() << "? (y/n)" << std::endl;
- std::cin >> resp;
- auto& answer = question.value()[resp == 'y' ? 0 : 1];
- if (answer.is_object()) {
- question = answer.begin();
- continue;
- }
- else {
- std::cout << answer.get<std::string>() << std::endl
- << "That's right? (y/n)" << std::endl;
- std::cin >> resp;
- if (resp == 'y') {
- std::cout << "Cool!" << std::endl;
- return 0;
- }
- else {
- std::cin.ignore();
- std::string a, b, c = answer.get<std::string>();
- std::cout << "What did you think?" << std::endl;
- std::getline(std::cin, a);
- std::cout << "How does it differ from " << c << '?' << std::endl;
- std::getline(std::cin, b);
- std::cout << "OK, I'll remember this!" << std::endl;
- answer = { {b, {a, c}} };
- }
- break;
- }
- }
- std::ofstream output("D://input.txt.tmp");
- output << j;
- output.close();
- std::filesystem::rename("D://input.txt.tmp", "D://input.txt");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement