C++中main函数的参数解析argc和argv是啥?
程序员文章站
2024-02-17 15:21:16
...
argc和argv是什么意思?
int main(int argc, char **argv)
{
return 0;
}
其中,
argc是argument count的简写,即参数个数; argv是argument value的简写,即参数值;
以ros编码为例
#include "ros/ros.h"
#include "beginner_tutorials/AddTwoInts.h"//AddTwoInts.h是重新编译beginner_tutorials包自动生成的
bool add(beginner_tutorials::AddTwoInts::Request &req,
beginner_tutorials::AddTwoInts::Response &res)
{
res.sum = req.a + req.b;
ROS_INFO("request: x=%ld, y=%ld", (long int)req.a, (long int)req.b);
ROS_INFO("sending back response: [%ld]", (long int)res.sum);
return true;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "add_two_ints_server");
ros::NodeHandle n;
ros::ServiceServer service = n.advertiseService("add_two_ints", add);//广告服务名add_two_ints
ROS_INFO("Ready to add two ints.");
ros::spin();
return 0;
}
其中,init中就用了argc和argv;
上一篇: Map排序