以下是一个实现代码的例子:

#include <iostream>
#include <string>

std::string removeTrailingSlash(std::string path) {
    if (path.back() == '/')
        path.pop_back();
    return path;
}

int main() {
    std::string directory = "/opt/test/";
    std::string result = removeTrailingSlash(directory);
    std::cout << "Result: " << result << std::endl;
    return 0;
}

在上面的代码中,removeTrailingSlash 函数接受一个路径字符串作为参数,并检查最后一个字符是否为斜杠(/),如果是的话就将其移除。然后,main 函数使用 /opt/test/ 作为示例路径,并调用 removeTrailingSlash 函数进行处理。最后,输出结果为 /opt/test

linux cc++ 目录最后是则去掉例如opttest去掉后为opttest 给出实现代码

原文地址: https://www.cveoy.top/t/topic/itYW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录