Skip to content

reading max double, throws bad conversion #229

@GoogleCodeExporter

Description

@GoogleCodeExporter
What steps will reproduce the problem?

#include <fstream>
#include <iostream>
#include <yaml-cpp/yaml.h>
using namespace std;

int main()
{
  double doubleVal;
  float floatVal;
  ofstream outYaml;
  YAML::Node writer;
  YAML::Node reader;

  // write
  writer["float"] = numeric_limits<float>::max();
  writer["double"] = numeric_limits<double>::max();
  outYaml.open("test.yaml");
  outYaml << writer;
  outYaml.close();

  // read
  reader = YAML::LoadFile("test.yaml");
  if (reader["float"])
  {
    floatVal = reader["float"].as<float>();
    cout << "float " << floatVal << endl;
  }
  if (reader["double"])
  {
    doubleVal = reader["double"].as<double>(); // throws bad conversion
    cout << "double " << doubleVal << endl;
  }
  return 0;
}


What is the expected output? What do you see instead?
reading max float is ok, but reading max double throws bad conversion

What version of the product are you using? On what operating system?
Using yaml-cpp 0.5.1 on Ubuntu 12.04 64-bit

Please provide any additional information below.


Original issue reported on code.google.com by lucky13...@gmail.com on 13 Dec 2013 at 7:36

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions