Closed
Description
How to use json parse from fstream?
1>------ Build started: Project: ConsoleApplication9, Configuration: Debug Win32 ------
1>ConsoleApplication9.cpp
1>\3rd-party\json\json.hpp(9592,1): error C2440: 'return': cannot convert from 'const _Ty2 *' to 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> *'
1> with
1> [
1> _Ty2=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1> ]
1>\3rd-party\json\json.hpp(9592,24): message : Conversion loses qualifiers
1>\3rd-party\json\json.hpp(9584): message : while compiling class template member function 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> *nlohmann::detail::iter_impl<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::operator ->(void) const'
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(4750): message : see reference to function template instantiation 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> *nlohmann::detail::iter_impl<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::operator ->(void) const' being compiled
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(4748): message : see reference to class template instantiation 'nlohmann::detail::iter_impl<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>' being compiled
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(4733): message : while compiling class template member function 'bool nlohmann::detail::json_sax_dom_callback_parser<BasicJsonType>::end_object(void)'
1> with
1> [
1> BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1> ]
1>\3rd-party\json\json.hpp(8847): message : see reference to function template instantiation 'bool nlohmann::detail::json_sax_dom_callback_parser<BasicJsonType>::end_object(void)' being compiled
1> with
1> [
1> BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1> ]
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(8737): message : see reference to class template instantiation 'nlohmann::detail::json_sax_dom_callback_parser<BasicJsonType>' being compiled
1> with
1> [
1> BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1> ]
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(8734): message : while compiling class template member function 'void nlohmann::detail::parser<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::parse(const bool,BasicJsonType &)'
1> with
1> [
1> BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1> ]
1>D:\dev\pawn.json\src\3rd-party\json\json.hpp(20750): message : see reference to function template instantiation 'void nlohmann::detail::parser<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::parse(const bool,BasicJsonType &)' being compiled
1> with
1> [
1> BasicJsonType=nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>
1> ]
1> 3rd-party\json\json.hpp(15661): message : see reference to class template instantiation 'nlohmann::detail::parser<nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>' being compiled
1>C:\Users\continue\source\repos\ConsoleApplication9\ConsoleApplication9\ConsoleApplication9.cpp(19): message : see reference to class template instantiation 'nlohmann::basic_json<ordered_map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>' being compiled
1>Done building project "ConsoleApplication9.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Code:
#include <iostream>
#include "json.hpp"
#include "ordered_map.hxx"
#include <fstream>
template<class Key, class T, class Ignore, class Allocator,
class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
class AllocatorPair = typename std::allocator_traits<Allocator>::template rebind_alloc<std::pair<Key, T>>,
class ValueTypeContainer = std::vector<std::pair<Key, T>, AllocatorPair>>
using ordered_map = tsl::ordered_map<Key, T, Hash, KeyEqual, AllocatorPair, ValueTypeContainer>;
using json = nlohmann::basic_json<ordered_map>;
int main()
{
std::ifstream file("1");
json j;
j.parse(file);
}