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 Answer
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?