📜  c++ tokenize string - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:58.685000             🧑  作者: Mango

代码示例1
#include 
#include 
#include 

using namespace std;

int main() {
   std::stringstream str_strm("Hello from the dark side");
   std::string tmp;
   vector words;
   char delim = ' '; // Ddefine the delimiter to split by

   while (std::getline(str_strm, tmp, delim)) {
      // Provide proper checks here for tmp like if empty
      // Also strip down symbols like !, ., ?, etc.
      // Finally push it.
      words.push_back(tmp);
   }
}