Defined in header <fkYAML/node.hpp>
fkyaml::basic_node::as_int¶
Returns (const) reference to the integer node value.
If the current node value is not an integer, a fkyaml::type_error
will be thrown.
Return Value¶
(const) reference to the integer node value.
Examples¶
Example
#include <iostream>
#include <fkYAML/node.hpp>
int main() {
// create a integer node.
fkyaml::node n = 123;
// get reference to the integer value from a non-const node.
// use `auto&` or `fkyaml::node::integer_type&` for forward compatibility.
auto& i = n.as_int();
// get const reference to the integer value from a const node.
const fkyaml::node cn = n;
const auto& ci = cn.as_int();
// modify the integer value.
i = 321;
std::cout << i << std::endl;
std::cout << ci << std::endl;
}
output: