比较从函数返回的两个std::string常量(两个json精神get_str())1-liner
comparing two std::string consts returned from functions (two json-spirit get_str()s) 1-liner
我正在使用json精神为我的ws-++服务器解析json。
我正在比较用于验证注册过程、已确认登录、电子邮件、密码等的字符串。
json精神的get_str()
返回const std::string&
。
我试过==
,compare
,甚至strcmp
。当我试图将函数返回与"1 liner"(全部在if
比较语句中)进行比较时,所有这些都会使程序与terminate called after throwing an instance of 'std::runtime_error' what(): value type is 0 not 2
崩溃。
这个函数可以使用1行返回吗?
这里只是猜测:我认为您的源json
并没有根据值的类型提供您所认为的内容。
我不熟悉json精神,但你的链接有这样一段话:
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精神认为你的字符串根本不是字符串。当您尝试对非字符串(定义为类型"0"的内容)调用get_str()
时,它会引发异常。
EDIT:在json精神的源代码中,类型"0"是NULL_type
- 如何在C++中从两个单独的for循环中添加两个数组
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 如何返回一个类的两个对象相加的结果
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 两个字符串在 c++ 中不相等
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 两个文件使用彼此的功能-如何解决
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 如何确保在使用基于布尔值的两个方法之一调用方法时避免分支预测错误
- 停止cmake target_link_libraries将插件中静态库的两个对象文件链接到静态库本身
- 将fold表达式与std::一起用于两个元组
- 如何在C++中比较两个char数组
- 给定两个偶数,求出它们之间所有偶数的平方和
- 比较两个大小不等的映射c++
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 增强精神Qi-列表解析具有两个组件序列
- 比较从函数返回的两个std::string常量(两个json精神get_str())1-liner
- 用替代操作员提升精神 '|' 失败!当有两个可能的规则要走时