#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
void func(
const string& template_file_path,
const string& output_file_path,
const string& str_marker,
const string& str_ip
)
{
vector< string > lines;
{
FILE* fp = fopen(template_file_path.c_str(), "r");
if (fp != NULL)
{
char ss[2345];
while (fgets(ss, 2345, fp))
{
string iline = ss;
auto result = iline.find(str_marker);
if (result != string::npos)
{
iline.replace(result, str_marker.size(), str_ip);
}
lines.push_back(iline);
}
fclose(fp);
}
}
{
FILE* fp = fopen(output_file_path.c_str(), "w");
if (fp != NULL)
{
for (auto& iline : lines)
{
fprintf(fp, "%s", iline.c_str());
}
fclose(fp);
}
}
return;
}
int main(int argc, char* argv[])
{
if (argc < 5)
{
cout << "usage: --";
return 0;
}
string template_file_path = argv[1];
string output_file_path = argv[2];
string str_marker = argv[3];
string str_ip = argv[4];
func(template_file_path, output_file_path, str_marker, str_ip);
return 0;
}