Sourcing a stored file and writing to output file in godbolt

377 Views Asked by At

I would like to modify the example provided by godbolt: https://godbolt.org/z/WseTsM8YG to create a project that reads from Isource.json input file and writes to Osource.json with all of the json files created and stored on the godbolt website/project itself.

I have gotten to https://godbolt.org/z/Ecxz6abEn but the code does not compile let alone allowing me to create the Isource.json file.

The code compiles and works fine on my local computer. The code is:

#include <boost/json.hpp>
using namespace boost::json;
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
#include <vector>
#include <iostream>
#include <fstream>

int main() {

    std::string fname = "Isource.json";
    //Read JSON file and store in json::object
    const path fileName(fname);
    object obj;
    std::ifstream file(fname);
    std::string content(std::istreambuf_iterator<char>{file}, std::istreambuf_iterator<char>{});
    value jv = parse(content);
    obj = jv.as_object();
    file.close();
        
    //Output to OSource.json
    fname = "Osource.json";
    std::ofstream ofile(fname);
    ofile << boost::json::value_from(obj);
    ofile.close();

}

I do not want this to be a cmake project and would like to build it using standard traditional g++ makefile. How can one create the needed Isource.json file and have godbolt create the output file (Osource.json) that can also be seen on the website itself? On my Windows computer using Visual Studio, I would store Isource.json in the same folder where the project/solution file exists and the above code would read that file and Osource.json would be created/written in the same folder.

0

There are 0 best solutions below