如何使用提升解析文件路径
How to parse filepath with boost?
我使用 boost::p rogram_options 和 boost::filesystem。我需要解析命令行参数。
int main(int argc, char** argv)
{
//command line arguments
variables_map vm;
try{
options_description desc{ "Program usage " };
desc.add_options()
("help,h", "Show help")
("input,I", value<std::string>(), "Input directory")
("output,O", value<std::string>(), "Output file ");
store(parse_command_line(argc, argv, desc), vm);
notify(vm);
如何将参数用作文件路径?
path file_path = vm.count["input"];
path file_path = vm.count["input"].as<std::string>();
不工作
您可以使用--input
分配命令行中提供的路径的值,以便file_path
:
if (vm.count("input")) {
std::string my_path = vm["input"].as<std::string>();
boost::filesystem::path file_path (my_path);
std::cout << "The input path is: " << file_path << std::endl;
}
希望这有帮助。
相关文章:
- 从函数角度看ID到文件路径的内部与外部映射
- 在C++中设置基于操作系统的文件路径
- Windows 非 ASCII 文件路径
- 非 ASCII 文件路径窗口
- C++和带有国家符号的文件路径(也许用 UTF8 编码)
- 如何为文件路径使用变量?
- 包括 VS Code 上的完整文件路径
- 如何使用提升获取当前文件路径?
- 如何在 c++ 中获取当前文件路径?
- 保存json文件后如何返回文件路径
- 从 C++ 中的文件路径中提取文件名
- 是否可以将文件路径传递给Qt中的setStyleSheet()
- 无法转换 .CATPart 文件.错误:输入文件路径似乎包含不支持的字符
- 在结构函数之间传递文件路径 C++ 编辑:修复LNK2019错误
- 提供依赖于输入的程序的文件路径
- 从 QFileSystemModel 中的文件路径和文件名获取 QModelIndex
- 如何更改变量文件名的文件路径?
- cmake:包括vs vs add_subDirectory:相对标头文件路径
- 在OSX中使用CGDisplayStream存储屏幕记录的特定文件路径
- 如何在另一个系统上启用文件路径