split string into container on char; efficiently?
First, consider passing potentially expensive-to-copy objects such as std::string as const reference rather than by-value. The obvious approach is to use std::istringstream and std::getline.

std::vector&lt;std::string&gt; split_uri(const std::string uri&amp;, char chr)
{
    std::istringstream iss(uri);
    std::vector&lt;std::string&gt; vec;

    for(std::string token; getline(iss, token, chr); )
        vec.push_back(token);

    return vec;
}


With the input being \bar\can, the output is {"", "bar", "can"}.

However, std::istringstream is not known for its speed. If you don't want to use std::istringstream, you don't have to. The following should be much faster:

std::vector&lt;std::string&gt; split_uri(const std::string&amp; uri, char chr)
{
    std::string::const_iterator first = uri.cbegin();
    std::string::const_iterator second = std::find(first+1, uri.cend(), chr);
    std::vector&lt;std::string&gt; vec;

    while(second != uri.cend())
    {
        vec.emplace_back(first, second);
        first = second;
        second = std::find(second+1, uri.cend(), chr);
    }

    vec.emplace_back(first, uri.cend());

    return vec;
}


With the input being \bar\can, the output is {"\bar", "\can"}.