Possible Duplicate:
How to split a string?
What is the right way to split a string into a vector of strings. Delimiter is space or comma.
Use std::string::find and std::string::substr Functions to Split String by Space in C++ find and substr are std::string builtin functions that can be utilized to split string by any delimiter specified by the string value or a single character.
In your code, stringw is of the type char * and so it is not compatible with the vector you have defined.
A convenient way would be boost's string algorithms library.
#include <boost/algorithm/string/classification.hpp> // Include boost::for is_any_of #include <boost/algorithm/string/split.hpp> // Include for boost::split // ... std::vector<std::string> words; std::string s; boost::split(words, s, boost::is_any_of(", "), boost::token_compress_on);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With