C++ directory_iterator
C++ directory_iterator
我已经有一段时间没有使用c++了,请原谅我向新手提出的问题。
我编写了以下代码来获取目录的内容列表,它工作得很好:for (directory_iterator end, dir("./");
dir != end; dir++) {
std::cout << *dir << std::endl;
}
"*dir"返回什么,一个指针的"字符数组",指针指向"字符串"对象,或指针指向"路径"对象?
我想传递"*dir"(如果它以.cpp结尾)给另一个函数(),该函数将在稍后的时间(异步)对其进行操作。我想我需要做一个"*dir"的拷贝。我写了下面的代码:
path *_path;
for (directory_iterator end, dir("./");
dir != end; dir++) {
_path = new path(*dir);
if (_path->extension() == ".cpp") {
function1(_path); // function1() will free _path
} else
free(_path);
}
谢谢你,艾哈迈德。
来自boost::directory_iterator:
的文档关于函数调用,我认为最简单的方法是:end迭代器上操作符*的结果没有定义。对于任何其他迭代器值:const directory_entry&返回.
using namespace boost::filesystem;
for (directory_iterator end, dir("./"); dir != end; dir++) {
const boost::filesystem::path &this_path = dir->path();
if (this_path.extension() == ".cpp") {
function1(this_path); // Nothing to free
}
}
其中function1方法可以声明为:
void function1(const boost::filesystem::path this_path);
相关文章:
- 如何在C++中找到active directory中禁用和锁定的窗口帐户
- Active Directory:从网络服务帐户下运行的Windows服务调用ADsOpenObject时失败
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 在调试模式下引发C++ "deque iterator not dereferencable"异常
- std::iterator::reference 必须是引用吗?
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- "Cannot find -l<directory>"错误 - CMake
- "No such file or directory" C++标头问题
- 为什么unordered_set<string::iterator>不起作用?
- 造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
- Visual accept std::string from std::byte iterator
- 我在 #include < bits/stdc++h.> 放置时出错"No such file or directory"
- 叮叮当当。target_include_directories "No such file or directory"
- 从生成文件编译错误:"Unable to open output file" ..."No such file or directory"
- C++编译期间出现"No such file or directory"错误
- 什么是"std::set<int,int>::iterator"?
- Implementing Active Directory with C++ Builder
- ECLIPSE makefile for C++ projects -- source directory
- 编写内核配置时"Not a directory"
- 从 std::vector 中删除项目时"Iterator not incrementable"