gpt4 book ai didi

c++ - 面向对象的替代 glob/globfree

转载 作者:行者123 更新时间:2023-11-28 03:08:44 27 4
gpt4 key购买 nike

我目前正在使用 glob将 UNIX 路径名与包含通配符的输入字符串进行匹配。我的脏代码如下所示:

glob_t gl;
int result = glob(inputString, GLOB_TILDE, NULL, &gl);
try {
// do whatever
} catch(...) {
globfree(&gl);
throw;
}
globfree(&gl);

我想知道在 C++ 中是否有更聪明的方法来完成这项工作。我一直在寻找一个类,它可以在析构函数或类似的东西中封装对 globfree 的调用,但没有找到任何现成的东西。

最佳答案

使用 http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/index.htm 是一种更智能的完全 C++ 方式来做你想做的事.
特别是 directory_iterator 可以帮助您完成您想要的。请看优tutorials关于如何使用它!

关于c++ - 面向对象的替代 glob/globfree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19032011/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com