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