C++ - Linux 中的 grep 路径

标签 c++ linux

我是 linux 新手,我想知道如何获取以下格式的路径 - /home/linux/sample/?

我想编写一个 c++ 函数,它将路径作为输入并返回 true,就好像路径有 /home/linux/sample/

示例:

如果路径是/home/linux/sample/test.txt应该返回true

如果路径是/home/linux/sample/dir 应该返回true

如果路径是/home/linux/user/test.txt应该返回false

有人能帮帮我吗?

提前致谢。

最佳答案

要编写这样的函数,您只需要 std::string:

string str ("There are two needles in this haystack.");
string str2 ("needle");

if (str.find(str2) != string::npos) {
//.. found.
} 

如果算法变得比我会转向正则表达式更复杂。

关于C++ - Linux 中的 grep 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32397821/

相关文章:

python - 在 Linux 上获取鼠标位置,纯 Python

linux - Apache 目录工作室的 Openldap 命名上下文问题?

c++ - 以毫秒为单位的本地时间

c++ - Qt 视频流应用程序 : no service found for qt. mediaplayer

C++ Map/Set 迭代器不可递增错误

C++:单例?如何将参数传递给构造函数?

php - 在我们自己的系统上获取并显示在不同操作系统上工作的访客 IP 地址

linux - 使用列中的引用拆分文件

c++ - 错误 : invalid conversion from `void*` to `void (*)()` in case of dlsysm

c++ - 我怎么知道在 OpenMP "for directive"中完成了多少作业?