How can I insert a character into a string exactly after 1 character?
I need to insert \'|\' into the string after every other char
I think I'd use a standard algorithm and iterator:
std::string add_seps(std::string const &input, std::string sep="|") {
std::ostringstream os;
std::copy(input.begin(), input.end(), std::ostream_iterator(os, sep));
return os.str();
}
As it stands, this adds a separator after the last character of the input. If you only want them between characters, you'd use an infix_ostream_iterator.