如何在 C++/CLI 中递归搜索目录

发布于 2024-12-11 18:59:25 字数 700 浏览 0 评论 0原文

谷歌搜索递归搜索的 Windows 示例,我发现 this 但尝试使用 cl 编译它(并且MSVC++ 工具链)编译器会指出错误之上的错误。当我不使用 MSVC++ GUI 完成的常规设置时,是否需要直接包含一些额外的库?

发布的示例错误代码已翻译,因此可能与英文版本不完全一样。

"*": This referencing cannot be done for System::String the compiler substitutes "*" by 
"^" to continue analysis

System::String ^ a system-owned array cannot contain this managed type

两个错误都在这一行

String* directories[] = Directory::GetDirectories(dir.c_str()); //dir is a usual string

,因此不是我的编码。

我搞砸了什么?

编译行是:

cl /w /c /clr file.cpp

Googling for an windows example of a recursive search i found this but trying to compile this with cl (and the MSVC++ tool chain) the compiler states error over error. Do I need to include some extra libraries directly as soon as i am not using the usual setup done by the MSVC++ GUI.

The posted example error codes are translated and therefore might not look exactly like they would in English.

"*": This referencing cannot be done for System::String the compiler substitutes "*" by 
"^" to continue analysis

and

System::String ^ a system-owned array cannot contain this managed type

both those errors are on this line

String* directories[] = Directory::GetDirectories(dir.c_str()); //dir is a usual string

and therefore are not my coding.

What am I messing up?

The compile-line was:

cl /w /c /clr file.cpp

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的黑色迷你裙 2024-12-18 18:59:26

Directory::GetDeictories 是一个 .net 调用,因此它将返回一个 .net 对象。您正在尝试将其转换为 C++ 指针。最好的选择是声明一个 .net 字符串数组。类型就像这样

array<String^>^ directories = Directory::GetDirectories(dir.c_str());

Directory::GetDeirectories is a .net call so it will return a .net object. You are trying to cast it to a c++ pointer. Your best bet is to declare a .net string array instead. The type is like so

array<String^>^ directories = Directory::GetDirectories(dir.c_str());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文