【C++】用 yaml 文件读写
https://blog.csdn.net/weixin_44088559/article/details/108587440
https://frank909.blog.csdn.net/article/details/89515470?spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-5-89515470-blog-111933856.t5_layer_eslanding_sa_randoms&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-5-89515470-blog-111933856.t5_layer_eslanding_sa_randoms&utm_relevant_index=10
https://blog.csdn.net/Fourier_Legend/article/details/82798297?spm=1001.2101.3001.6650.12&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-12-82798297-blog-89515470.t0_searchtargeting_v1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-12-82798297-blog-89515470.t0_searchtargeting_v1&utm_relevant_index=16
yaml 文件
param_a: 99
param_b: "sfsdf"
param:
param_c: 100
CMakists.txt
add_executable(yat yaml_test.cpp)
target_link_libraries(yat
yaml-cpp
)
cpp文件
#include <iostream> #include "yaml-cpp/yaml.h" int main(int argc, char * argv[]) { std::string pathplanning_behavior_tree_yaml_path = "../param/param_test.yaml"; // 相对路径 是可执行文件所在路径 YAML::Node pathplanning_behavior_tree_config = YAML::LoadFile(pathplanning_behavior_tree_yaml_path); double a = pathplanning_behavior_tree_config["param_a"].as<double>(); std::string b = pathplanning_behavior_tree_config["param_b"].as<std::string>(); double c = pathplanning_behavior_tree_config["param"]["param_c"].as<double>(); std::cout << " a " << a << " b " << b << " c " << c << std::endl; // a 99 b sfsdf c 100 return 0; }