I am doing a C++ coding exercise, as usual…. And to split a string in C++, the best/easy way is to use the boost library… However, this is not supported on leetcode online judge…
C++ without boost library, is a bit hard to learn and use.
How to Split a String by Delimiter in C++ using Boost Library?
Take this for example, you can easily use boost::split to split a string into vector of string by a set of delimiters, like this:
1 2 3 | #include <boost/algorithm/string.hpp> vector<string> str; boost::split(str, "string to , split", boost::is_any_of(" ,")); |
#include <boost/algorithm/string.hpp> vector<string> str; boost::split(str, "string to , split", boost::is_any_of(" ,"));
This is straightforward and easy to use, similar to other modern programming languages. I hope the boost library can be used by the leetcode and also other online judges e.g. Timus. As it brings conveniences and avoids re-inventing the wheel. It allows us to focus on solving the puzzles. However, this can be disabled for coding exercises related to e.g. implementing the string split function.
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: How to Check Any String is Palindrome from Its Permutation?
Next Post: C++ Coding Exercise - Subdomain Visit Count