It is possible to turn the string into a stream by using the std::stringstream class (its constructor takes a string as parameter). Once it’s built, you can use the >> operator on it (like on regular file based streams), which will extract, or tokenize word from it:
#include
#include
using namespace std;
int main(){
string line = “test one two three.”;
string arr[4];
int i = 0;
stringstream ssin(line);
while (ssin.good() && i < 4){
ssin >> arr[i];
++i;
}
for(i = 0; i < 4; i++){
cout << arr[i] << endl;
}
}
#include
#include
#include
#include
using namespace std;
template
void splitString(string (&arr)[N], string str)
{
int n = 0;
istringstream iss(str);
for (auto it = istream_iterator