#include <fstream>
#include <sstream>
std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) { size_t start_pos = 0; while ((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); // Handles case where 'to' is a substring of 'from' } retu str;
}
int main(int argc, char *argv[])
{ const std::string file_name = R"(D:readme.txt)"; std::ifstream filei(file_name); std::string line; std::string src_str = "ali"; std::string dst_str = "reza"; std::string wholeFile; if (filei.is_open()) { std::stringstream buffer; buffer << filei.rdbuf(); wholeFile = buffer.str(); filei.close(); wholeFile = ReplaceAll(wholeFile, src_str, dst_str); std::ofstream fileo(file_name); std::stringstream ss; ss.str(wholeFile); fileo << ss.rdbuf(); fileo.close(); }
}
+ نوشته شده در چهارشنبه 26 دی 1397 ساعت: 23:44 توسط محمد رضا جوادیان
برچسب ها:
|