Replace all instances of \ with / My main goal is to perform the conversion on a list of strings. Is this a sensible approach or should I refactor?

Please note that I cannot use Boost in my work.

#include &lt;iostream&gt;
#include &lt;list&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;


char fix_delim(char ch) {
    return ch == '\\' ? '/' : ch;
}

std::string&amp; fix_str(std::string&amp; str) {
   std::transform(str.begin(), str.end(), str.begin(), fix_delim);
   return str;
}

int main() {
   std::list&lt;std::string&gt; files;
   files.push_back("folder\\file1");
   files.push_back("folder\\file2");

   //simple example of fix_delim
   std::string one("folder\\file1");
   std::transform(one.begin(), one.end(), one.begin(), fix_delim);

   //Is this a good way to solve this problem of replacing all instances of \ with / in a list of strings?
   std::transform(files.begin(), files.end(), files.begin(), fix_str);

   return 0;
}
Seems to me that the right algorithm for this job is std::replace:

std::replace(input.begin(), input.end(), '\\', '/');


The easiest way to apply to a collection of strings is probably to use std::for_each with a lambda:

std::for_each(files.begin(), files.end(), 
              [](std::string &amp;s) { std::replace(s.begin(), s.end(), '\\', '/'); });


If you can't use a lambda, you can write a tiny function object instead:

class path_dos2unix {
    void operator()(std::string &amp;s) {  
        std::replace(s.begin(), s.end(), '\\', '/');
    }
};


...and then invoke that:

std::for_each(files.begin(), files.end(), path_dos2unix());