无效标量十六进制值 0x8000000 及以上
我发现从 yaml 文件获取十六进制值时出现问题。它无法获取 0x80000000 及以上的十六进制值。 以下是一个示例 C++ 程序。
// ymlparser.cpp
#include <iostream>
#include <fstream>
#include "yaml-cpp/yaml.h"
int main(void)
{
try {
std::ifstream fin("hex.yaml");
YAML::Parser parser(fin);
YAML::Node doc;
parser.GetNextDocument(doc);
int num1;
doc["hex1"] >> num1;
printf("num1 = 0x%x\n", num1);
int num2;
doc["hex2"] >> num2;
printf("num2 = 0x%x\n", num2);
return 0;
} catch(YAML::ParserException& e) {
std::cout << e.what() << "\n";
}
}
hex.yaml
hex1: 0x7FFFFFFF
hex2: 0x80000000
错误消息在这里。
$ ./ymlparser
num1 = 0x7fffffff
terminate called after throwing an instance of 'YAML::InvalidScalar'
what(): yaml-cpp: error at line 2, column 7: invalid scalar
Aborted
环境
yaml-cpp :从 svn、2010 年 3 月 22 日或 v0.2.5 获取
操作系统:Ubuntu 9.10 i386
我现在需要获取 yaml-cpp 上的十六进制值,但我不知道。 请告诉我如何以其他方式获得它。
谢谢,
I found a problem getting hex value from yaml file. It couldn't get hex value 0x80000000 and over.
Following is a sample C++ program.
// ymlparser.cpp
#include <iostream>
#include <fstream>
#include "yaml-cpp/yaml.h"
int main(void)
{
try {
std::ifstream fin("hex.yaml");
YAML::Parser parser(fin);
YAML::Node doc;
parser.GetNextDocument(doc);
int num1;
doc["hex1"] >> num1;
printf("num1 = 0x%x\n", num1);
int num2;
doc["hex2"] >> num2;
printf("num2 = 0x%x\n", num2);
return 0;
} catch(YAML::ParserException& e) {
std::cout << e.what() << "\n";
}
}
hex.yaml
hex1: 0x7FFFFFFF
hex2: 0x80000000
Error message is here.
$ ./ymlparser
num1 = 0x7fffffff
terminate called after throwing an instance of 'YAML::InvalidScalar'
what(): yaml-cpp: error at line 2, column 7: invalid scalar
Aborted
Environment
yaml-cpp : getting from svn, March.22.2010 or v0.2.5
OS : Ubuntu 9.10 i386
I need to get hex the value on yaml-cpp now, but I have no idea.
Please tell me how to get it another way.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有符号整型的最大值实际上是
0x7FFFFFFF
。我很确定这就是问题所在。如果您只想得到正数,请尝试使用
unsigned int
。或者对有符号和无符号的数字使用long long
。The maximum value for a signed int is effectively
0x7FFFFFFF
. I am pretty sure that is the problem.Try using
unsigned int
if you are only going to get positive numbers. Or uselong long
for both, signed and unsigned numbers.