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 <iostream>
#include <list>
#include <string>
#include <algorithm>
char fix_delim(char ch) {
return ch == '\\' ? '/' : ch;
}
std::string& fix_str(std::string& str) {
std::transform(str.begin(), str.end(), str.begin(), fix_delim);
return str;
}
int main() {
std::list<std::string> 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;
}