tokenize
Tokenizing strings in C
Do it like this: Note: strtok modifies the string its tokenising, so it cannot be a const char*.
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?
What is the easiest/best/most correct way to iterate through the characters of a string in Java?
I use a for loop to iterate the string and use charAt() to get each character to examine it. Since the String is implemented with an array, the charAt() method is a constant time operation. That’s what I would do. It seems the easiest to me. As far as correctness goes, I don’t believe that exists here. It is … Read more
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