Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"C++47: Finally, a Standard Way to Split a String by Delimiter"


There's been this since 1998, likely earlier:

    std::vector<std::string> split(const std::string& text, char delimiter) {
        std::vector<std::string> parts;
        std::istringstream stream(text);
        std::string part;
        while (std::getline(stream, part, delimiter)) {
            parts.push_back(part);
        }
        return parts;
    }


A standard way to split a string? Well, what's wrong with:

    std::views::split(my_string, delimeter)

?


Template bloat, terrible compile errors, terrible debug build performance, 1 second of extra compile time per cpp file when you include ranges, and you can't step through it in a debugger.


None of these complaints detract from this being a terse, readable, and available using the standard library, which is what the question was about...

I will agree that std::ranges is quite a jumble of templates, and has a compilation time penalty. Perhaps the use of modules will help with that somewhat.


> you can't step through it in a debugger.

What do you mean by that?


I'm still waiting for C++ to support Unicode properly.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: