[Solved] equivalent of this in STL [closed]


This uses std::for_each() because you asked for STL:

#include <string.h>
#include <string>
#include <algorithm>

void inlineConvertPackFilename(std::string& name)
{
    std::for_each(name.begin(), name.end(), [](auto& c) {
        if (c == '\\')
        {
            c="https://stackoverflow.com/";
        }
        else
        {
            c = tolower(c);
        }
    });
}


int main()
{
    static std::string filename("C:\\FOO\\bar\\Baz.txt");
    inlineConvertPackFilename(filename);
    return 0;
}

But that’s really unnecessary as you can use a range for instead:

void inlineConvertPackFilename(std::string& name)
{
    for (auto& c : name)
    {
        if (c == '\\')
        {
            c="https://stackoverflow.com/";
        }
        else
        {
            c = tolower(c);
        }
    }
}

solved equivalent of this in STL [closed]