用boost库写一个获取路径中文件的名称的代码,例如文件路径为:/mnt/data/LCC/rosbag/test105/calib/2.jpg,需要返回2.jpg。
#include <boost/filesystem.hpp>
#include <iostream>
using namespace std;
int main()
{
// 定义文件路径
boost::filesystem::path filePath("/mnt/data/LCC/rosbag/test105/calib/2.jpg");
// 获取文件名
std::string fileName = filePath.filename().string();
// 输出文件名
std::cout << "File Name: " << fileName << std::endl;
return 0;
}
File Name: 2.jpg