How to split string using istringstream with other delimiter than whitespace?

Generally speaking the istringstream approach is slow/inefficient and requires at least as much memory as the string itself (what happens when you have a very large string?). The C++ String Toolkit Library (StrTk) has the following solution to your problem:

#include <string>
#include <vector>
#include <deque>
#include "strtk.hpp"
int main()
{
   std::string sentence1( "Cpp is fun" );
   std::vector<std::string> vec;
   strtk::parse(sentence1," ",vec);

   std::string sentence2( "Cpp,is|fun" );
   std::deque<std::string> deq;
   strtk::parse(sentence2,"|,",deq);

   return 0;
}

More examples can be found Here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)