Split a string into an array in C++

By the way, use qualified-names such as std::getline, std::ifstream like I did. It seems you’ve written using namespace std somewhere in your code which is considered a bad practice. So don’t do that: Why is “using namespace std” considered bad practice?

How do I tokenize a string in C++?

C++ standard library algorithms are pretty universally based around iterators rather than concrete containers. Unfortunately this makes it hard to provide a Java-like split function in the C++ standard library, even though nobody argues that this would be convenient. But what would its return type be? std::vector<std::basic_string<…>>? Maybe, but then we’re forced to perform (potentially redundant and costly) … Read more

Parse (split) a string in C++ using string delimiter (standard C++)

You can use the std::string::find() function to find the position of your string delimiter, then use std::string::substr() to get a token. Example: The find(const string& str, size_t pos = 0) function returns the position of the first occurrence of str in the string, or npos if the string is not found. The substr(size_t pos = 0, size_t n = npos) function returns a substring of the object, … Read more