0

I have to do this one problem as an admission exam to this programming academy. It's about reading .json files and telling the user what packages need to be installed first as dependencies. Here is a link to the problem. However, I'd never heard of such terms before (dependency, .json file, and I have limited programming experience), so my question is how do I access those .json files in order to see what dependencies need to be installed? I think I can come up with a backbone if I know how to access those files. Since I have zero experience with that stuff, any advice would be helpful.

1
  • The problem has examples of JSON, but there's always the million other resources on it. It's a very popular format. Commented Nov 12, 2015 at 0:01

1 Answer 1

1

You're asking how to read a json file, so here it goes:

// This will actually read any file, not just .json
std::ifstream in(filePath, std::ios::in | std::ios::binary);
std::ostringstream contents;
contents << in.rdbuf();
in.close();
std::string jsonString = contents.str();

Where filePath is the file's path.

It's as simple as that.

Now, to deserialize it into something useful... Well, that's another question, isn't it?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.