要获取"/opt/file_video_orig/"前面的字符串,可以使用C++的字符串处理函数和算法来实现。以下是一种可能的实现方式:

#include <iostream>
#include <string>

int main() {
    std::string input = "hdfs://192.168.100.1:9000/opt/file_video_orig/C/test1/libRcfDll.so";

    // 查找\"/opt/file_video_orig/\"的位置
    size_t pos = input.find("/opt/file_video_orig/");
    if (pos != std::string::npos) {
        // 提取前面的字符串
        std::string result = input.substr(0, pos);
        std::cout << result << std::endl;
    } else {
        std::cout << "找不到指定的字符串" << std::endl;
    }

    return 0;
}

输出结果为:

hdfs://192.168.100.1:9000

这段代码先使用find函数查找"/opt/file_video_orig/"的位置,如果找到了,则使用substr函数提取前面的字符串。如果找不到指定的字符串,则输出提示信息。

C++ 获取字符串中特定子串前面的部分 - 详细代码示例

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

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