linux c++字符串Gtestfile_c 去掉file_c给出实现代码
以下是一个简单的实现代码,用于删除字符串中的"file_c/":
#include <iostream>
#include <string>
void removeSubstrs(std::string& s, const std::string& p) {
std::string::size_type n = p.length();
for (std::string::size_type i = s.find(p); i != std::string::npos; i = s.find(p))
s.erase(i, n);
}
int main() {
std::string str = "linux c++字符串G/test/file_c/";
std::string pattern = "file_c/";
removeSubstrs(str, pattern);
std::cout << "删除后的字符串:" << str << std::endl;
return 0;
}
这段代码定义了一个removeSubstrs函数,用于删除字符串中的特定子字符串。然后在main函数中调用该函数,将要处理的字符串和要删除的子字符串作为参数传递进去。最后输出删除后的字符串
原文地址: http://www.cveoy.top/t/topic/izvS 著作权归作者所有。请勿转载和采集!