/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* main.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos #include int main(int argc, char **argv) { std::string filename; std::string s1; std::string s2; std::string line; if (argc == 4) { filename = argv[1]; s1 = argv[2]; s2 = argv[3]; line = ""; std::ifstream infile(filename.c_str(), std::ifstream::in); if (!infile.is_open()) { std::cout << "Ha ocurrido un error en el infile" << std::endl; return (1); } std::ofstream outfile((filename + ".replace").c_str()); if(!outfile.is_open()) { std::cout << "Hubo un error en el outfile" << std::endl; return (1); } while (std::getline(infile, line)) { size_t pos = 0; while ((pos = line.find(s1, pos)) != std::string::npos) { line.erase(pos, s1.length()); line.insert(pos, s2); pos += s2.length(); } outfile << line << std::endl; } infile.close(); outfile.close(); } else { std::cout << "Uso: ./sed " << std::endl; } return (0); }