首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比较函数返回的两个std::string常量(两个json-spirit get_str()) 1-liner

比较函数返回的两个std::string常量(两个json-spirit get_str()) 1-liner
EN

Stack Overflow用户
提问于 2013-07-09 09:18:26
回答 1查看 466关注 0票数 0

我正在使用json-spirit为我的ws++服务器解析json。

我正在比较用于验证注册过程、确认登录、电子邮件、密码等的字符串。

json-spirit的get_str()返回const std::string&

我试过==compare,甚至strcmp。当我尝试将函数返回与“1linder”(都在if比较语句中)进行比较时,terminate called after throwing an instance of 'std::runtime_error' what(): value type is 0 not 2会使程序崩溃。

这个函数可以使用1行代码返回吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-09 09:30:19

猜测一下:我认为您的源json并没有提供您认为的值类型方面的信息。

我不熟悉json-spirit,但您的链接中有这样一段:

You obtain the Value's type by calling Value::type(). You can then call the appropriate getter function. Generally, you will know a file's format, so you will know what type the JSON values should have. A std::runtime_error exception is thrown if you try to get a value of the wrong type, for example, if you try to extract a string from a value containing an integer.

这听起来与您看到的错误非常相似。我猜json-spirit认为你的字符串根本不是字符串。当你试图在不是字符串的东西上调用get_str()时(不管什么定义为“0”类型),它会抛出一个异常。

编辑:在json-spirit's source中查找,键入"0“是NULL_TYPE

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17538465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档