解决C++调用Json报的参数数量错误---json.hpp:6057:62: error: wrong number of template arguments

1.Problems

在编译一个调用json.hpp的程序时报错,报错如下:

/usr/include/nlohmann/json.hpp: In function ‘bool nlohmann::operator<(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference)’:
/usr/include/nlohmann/json.hpp:6057:62: error: wrong number of template arguments (1, should be 2)
return *lhs.m_value.array < *rhs.m_value.array;
^~~~~

就是提示参数应该有两个,其实这个挺奇怪的,之前我另一个程序编译没有问题,现在这个程序一编译就报这个错。

2. Solutions

解决方法也简单,现在出问题的是json 2.1.1版本,升级为3.11.2就可以了,可以去GitHub找原本,更方便的方法,直接把json.hpp给替换了就行
1)cd /usr/include/nlohmann
2)sudo cp json.hpp json_bak.hpp先备份一个,有任何问题就改回来
3)sudo gedit json.hpp 然后就把新版本的内容复制进去就可以了,如果没找到可以下载我放在资源里的3.11.2版本,点这里
4)然后修改完记得保存,之后如果引起别的问题,就把json_bak.hpp的内容复制回json.hpp就可以了
5)最后再次编译,应该就没问题了

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值