Skip to content

Question: return static json object from function #618

Description

Hi,
forgive me but I'm a newbie with c++ in general.

I'm trying to use this library but I have a problem.
I have a file like this:

static json config;

json get_config()
{
   config["value"] = 456;
   return config;
}

void save_config()
{
   std::ofstream fout("config.txt");
   fout << std::setw(3) << config << std::endl;
}

in another file I do something like ...

auto obj = get_config();
obj["value"] = 123;
save_config();

but inside config.txt i still see old value (456).
How can I solve this ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions