我是 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/