c++外输入参数设置(yaml + argv)

动机:
  • 在串联工具链时,由于参数可能过多,这时我们需要将变动不太频繁的输入参数,写到yaml中。
  • 变动频繁的参数,我们用argv进行输入
YAML

在config.yaml中写配置文件
语法详见C++读写yaml配置文件
将yaml中读取的参数存入全局变量中

// load yaml
YAML::Node config = YAML::LoadFile("/home/weicheng/hesai/hesai_sdk_intergration/test/config.yaml");
// std::string pcap_path = config["pcap_path"].as<string>();
std::string correction_path = config["correction_path"].as<string>();
// std::string output_bag = config["output_bag"].as<string>();
std::string topic_name = config["topic_name"].as<string>();
int start_angle = config["start_angle"].as<int>();

Tins::PacketWriter writer("./new_03.pcap", Tins::DataLinkType<Tins::EthernetII>());

config.yaml文件

# pcap_file path
pcap_path: /home/weicheng/Downloads/RFL03_008.pcap

# start angle
start_angle: 9

# correction file path
correction_path: /home/weicheng/Downloads/PA6430C5509530C554-correction.csv

# output bag
output_bag: test.bag

# topic name
topic_name: /hesai_RF02
argv
  • argc 是 argument count的缩写,表示传入main函数的参数个数;
  • argv 是 argument vector的缩写,表示传入main函数的参数序列或指针,并且第一个参数argv[0]一定是程序的名称,并且包含了程序所在的完整路径,所以确切的说需要我们输入的main函数的参数个数应该是argc-1个;
$ ./Pandargenral "input_path" "output_path"
int main(int argc, char **argv)
{
	std::string input_path = argv[1];
	std::string output_path = argv[2];
}

注意:
在编写工具链时,经常会遇到下一个文件的输入是上一个工具链的输出。
遇到这种情况时,可以使用相对路径,作为下一个工具的输入
不指定输出位置时,输出位置为build
./ 当前文件夹路径
. .、上一级文件夹路径

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值