J
Jason Heyes
I would like to modify the contents of a file, replacing all occurances of
one string with another. I wrote these functions:
bool read_file(std::string name, std::string &s);
bool write_file(std::string name, const std::string &s);
void find_replace(std::string &s, std::string first, std::string second);
bool find_replace_file(std::string name, std::string first, std::string
second)
{
std::string s;
if (!read_file(name, s))
return false;
find_replace(s, first, second); // replace first with second in s
return write_file(name, s);
}
Have I got the right idea? If not, what is wrong? Thanks.
one string with another. I wrote these functions:
bool read_file(std::string name, std::string &s);
bool write_file(std::string name, const std::string &s);
void find_replace(std::string &s, std::string first, std::string second);
bool find_replace_file(std::string name, std::string first, std::string
second)
{
std::string s;
if (!read_file(name, s))
return false;
find_replace(s, first, second); // replace first with second in s
return write_file(name, s);
}
Have I got the right idea? If not, what is wrong? Thanks.