rapidjson write stringbuffer to file

rapidjson write stringbuffer to file in C++

#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include <iostream>
#include <fstream>

int main() {
    rapidjson::StringBuffer s;
    rapidjson::Writer<rapidjson::StringBuffer> writer(s);

    writer.StartObject();
    writer.Key("hello");
    writer.String("world");
    writer.EndObject();

    std::ofstream ofs("output.json");
    ofs << s.GetString();
    ofs.close();

    return 0;
}