Skip to content

Segmentation fault on saving json to file #326

Closed
@aeon0

Description

I get a segmentation fault when saving a json data object to a file like this:

#include <iostream>
#include <fstream>
#include "json.hpp"

bool SaveToFile(nlohmann::json data) {
    std::ofstream jsonFile;

    jsonFile.open("testFile.json" , std::ofstream::out | std::ofstream::trunc);
    jsonFile << data;
    jsonFile.close();

    return true;
}

int main() {
    std::cout << "========== Start Application ===========" << std::endl;

    return 0;
}

The problem is, I cant even debug anything. Because even if I don't use the function I get the segmentation fault.
When changing: jsonFile << data; to jsonFile << "Test String";, I dont get any errors.

I am using Visual GDB with gcc 4.9.2 (from here: http://gnutoolchains.com/raspberry/).

Please ask if any other information or clarification is needed!

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions