You can use std::string::replace
, if you intention is to replace all occurences of eof
substring with \0
then I suggest using standard method as in:
https://en.cppreference.com/w/cpp/string/basic_string/replace
std::size_t replace_all(std::string& inout, std::string_view what, std::string_view with)
{
std::size_t count{};
for (std::string::size_type pos{};
inout.npos != (pos = inout.find(what.data(), pos, what.length()));
pos += with.length(), ++count) {
inout.replace(pos, what.length(), with.data(), with.length());
}
return count;
}
Your code should look as follows:
std::string buffer = "eof";
replace_all(buffer, "eof", "\0");
https://coliru.stacked-crooked.com/a/4110765b0f265aae