tags:

views:

79

answers:

1

Hi.

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,

+3  A: 

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 use long long for both, signed and unsigned numbers.

Anzurio
Anzurio,Thanks for your help. It is correct! I could get 0x80000000.
kioto
@kioto, the best way to say that around here is to click the checkmark to accept the answer. :-)
Kristo