What's the simplest way to use a delimiter to separate string values and store it in an array in C++?

array
array-string
c-plus-plus
java
string

#1

Sort of like the String class split() function in Java? Does a similar easy alternative exist in C++?


#2

You can use stringstream in c++.

vector<string> v;
string a,b;
getline(cin,a);
istringstream ss(a);
while(getline(ss,b,' ')){
   v.push_back(b);
}

#3

@ay2306 There isn’t a similar easier alternative then, I’m guessing. This is a more streamlined approach than using plain substrings (although underlying idea is same), so it’s not too bad.