以下是一个示例代码,用于从字符串中去掉 "G/test/file_c/",并输出结果:

#include <iostream>
#include <string>

std::string removeSubstring(std::string str, const std::string& substr) {
    size_t pos = str.find(substr);
    while (pos != std::string::npos) {
        str.erase(pos, substr.length());
        pos = str.find(substr, pos);
    }
    return str;
}

int main() {
    std::string str = "G/test/file_c/abc/G/test/file_c/def/G/test/file_c/ghi";
    std::string substr = "G/test/file_c/";

    std::string result = removeSubstring(str, substr);
    std::cout << result << std::endl;

    return 0;
}

运行该代码将输出字符串 "abc/def/ghi",其中 "G/test/file_c/" 已被移除

linux c++去掉Gtestfile_c 去掉file_c给出实现代码

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

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