"retsize <= sizeInWords" in mbstowcs in dirent.
"retsize <= sizeInWords" in mbstowcs in dirent.h on Windows
>背景信息:
我正在使用VS2013上的dirent.h(项目要求)在窗口中构建文件树。我从这里得到了dirent.h。我在运行时崩溃,调试断言失败("retsize <= sizeInWords"),来自crt\crtw32\mbstowcs.c,第283行。
为了测试dirent.h,我使用了
void printDir(std::string dir, std::string tab)
{
DIR* d = opendir(dir.c_str());
dirent* ent = nullptr;
while (ent = readdir(d)) {
if (ent->d_name[0] != '.') {
std::cout << tab << ent->d_name << std::endl;
if (ent->d_type == DT_DIR) {
printDir(dir + "/" + ent->d_name, tab + " ");
}
}
}
}
它有效(从主称为 printDir(".", "))
所以为了建立我的树,我有:
struct Dirf {
std::string getFullPath() {
if (out) {
return out->getFullPath() + "/" + ent.d_name;
}
else return ent.d_name;
}
Dirf(DIR* dir, Dirf* parent = nullptr)
: out(parent)
{
if (dir) {
dirent* d = readdir(dir);
if (d) {
ent = *d;
if (dir) {
next = std::make_shared<Dirf>(dir, parent);
}
if (ent.d_type == DT_DIR) {
DIR* inDir = opendir(getFullPath().c_str());
in = std::make_shared<Dirf>(inDir, this);
closedir(inDir);
}
}
}
}
private:
typedef std::shared_ptr<Dirf> point;
friend std::string to_string(Dirf, std::string);
dirent ent;
Dirf* out; // parent to this; in->out == this, out->in == this;
point in, // in != null iff car.d_type == DT_DIR
next; // next entry in the dir
};
std::string to_string(Dirf, std::string tab = "");
但是,调用 Dirf(opendir(".")) 失败,并显示上述调试断言
在编写问题时,我想出了答案:我忘了在 Dirf 的构造函数中检查"."和".."(我记得在我的测试用例中这样做)。添加
while (d && d->d_name[0] == '.') { // skip '..' and '.'
d = readdir(dir);
}
dirent* d = readdir(dir)
之后,错误消失了。
相关文章:
- netcat command in c++
- Difference in displaying cv2 Mat
- C++ MFC Libraries in Travis CI
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 创建具有 new in 函数和"this is nullptr"异常的对象
- IN, OUT, INOUT Parameters
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 有人安装"IITB Simplecpp in mac"吗?
- 从 C 样式字符串中删除子字符串 "in place" 在C++代码中
- 如何修复"error: ‘_1’ was not declared in this scope"?
- Softmax Implementation in C++
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- IF-nesting in c++
- Gurobi GRBModel and GRBmodel in C++
- Tensorflow Hub in C++
- Centos7 g++ "to_string is not in a member of std"
- InitializeCriticalSectionEx Not Located In KERNEL32.Dll
- 将 lambda 表达式传递给 std::function in C++
- @CPPFLAGS@在 Makefile.in 中意味着什么?
- std::async from std::async in windows xp