【发布时间】:2020-04-28 07:08:14
【问题描述】:
如何将我的函数从 const char* 转换为字符串?我需要它没有模板。只需在 pattern_founder(std::string, std::string) 上重建我的函数 pattern_founder(const char*, const char*)。我试图用迭代器来做,但是出了点问题。谢谢。
static bool pattern_founder(const char* file_path_ptr, const char* pattern) noexcept
{
const char* supp_file_path_ptr = nullptr;
const char* supp_pattern = nullptr;
while (true)
if (*pattern == '*') {
supp_file_path_ptr = file_path_ptr;
supp_pattern = ++pattern;
}
else if (!*file_path_ptr)
return !*pattern;
else if (*file_path_ptr == *pattern || *pattern == '?') {
++file_path_ptr;
++pattern;
}
else if (supp_file_path_ptr) {
file_path_ptr = ++supp_file_path_ptr;
pattern = supp_pattern;
}
else
return false;
}
【问题讨论】:
-
您能描述一下代码的用途吗?
-
请向我们展示您的尝试并解释出了什么问题,我们将帮助您解决问题。但 SO 不是免费的代码编写服务。
-
@JasperKent,好的。这段代码比较两个 C 风格的字符串,并告诉我们在 file_path_ptr 中是否有模式。模式是带有特殊小丑的文件名或文件路径。现在,我编写程序,就像您在 Windows 上的资源管理器中看到的那样,您放置一些行,例如“hello.cpp”,prohramm 比较所有变体并为您提供可能的选项。附:对不起我的英语:#
标签: c++ c++11 visual-c++ c++14 c++17