user3766148
user3766148

Reputation:

error: conversion from 'const char [10]' to non-scalar type 'std::fstream {aka std::basic_fstream<char>}' requested

I am trying to import a test JSON file and parse it. I keep getting the wrong data type. How do I load a 'const char' friendly file?

code:

#include "include/rapidjson/document.h"
#include <iostream>
#include <cstring>
#include <string>
#include <fstream>

using namespace std;
using namespace rapidjson;

int main(void){

        //std::ofstream outfile ("test.json");
        std::fstream file = ("test.json");

        for (int n=0; n<100; ++n)
        {
                file << n;


                Document document;
                document.Parse(file);

                assert(document.HasMember("hello"));
                assert(document["hello"].IsString());
                printf("hello = %s\n", document["hello"].GetString());

                outfile.flush();
                //outfile.close();

        }
}

error:

error: conversion from 'const char [10]' to non-scalar type 'std::fstream {aka std::basic_fstream<char>}' requested

Upvotes: 0

Views: 1767

Answers (1)

Anton Savin
Anton Savin

Reputation: 41301

Try

std::fstream file("test.json");

As for this

document.Parse(file);

Document::Parse() takes const char*, and you are trying to pass an fstream instead. Perhaps you can use ParseStream() instead. Or read all contents from the file and pass it to Parse().

Upvotes: 3

Related Questions