Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::as_float¶
Returns (const) reference to the float node value.
If the current node value is not a floating point value, a fkyaml::type_error
will be thrown.
Return Value¶
(const) reference to the float node value.
Examples¶
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
// create a float node.
fkyaml::node n = 3.14;
// get reference to the float value from a non-const node.
// use `auto&` or `fkyaml::node::float_number_type&` for forward compatibility.
auto& f = n.as_float();
// get const reference to the float value from a const node.
const fkyaml::node cn = n;
const auto& cf = cn.as_float();
// modify the float value.
f = 1.41;
std::cout << f << std::endl;
std::cout << cf << std::endl;
}
output: