Skip to main content
Post Made Community Wiki by softghost
added 42 characters in body
Source Link
user246110
user246110

Here's another way of doing it..

void split_string(string text,vector<string>& words)
{
  int i=0;
  char ch;
  string word;

  while(ch=text[i++])
  {
    if (isspace(ch))
    {
      if (!word.empty())
      {
        words.push_back(word);
      }
      word = "";
    }
    else
    {
      word += ch;
    }
  }
  if (!word.empty())
  {
    words.push_back(word);
  }
}

Here's another way of doing it..

void split_string(string text,vector<string>& words)
{
 int i=0;
 char ch;
 string word;

 while(ch=text[i++])
 {
  if (isspace(ch))
  {
   if (!word.empty())
   {
    words.push_back(word);
   }
   word = "";
  }
  else
  {
   word += ch;
  }
 }
 if (!word.empty())
 {
  words.push_back(word);
 }
}

Here's another way of doing it..

void split_string(string text,vector<string>& words)
{
  int i=0;
  char ch;
  string word;

  while(ch=text[i++])
  {
    if (isspace(ch))
    {
      if (!word.empty())
      {
        words.push_back(word);
      }
      word = "";
    }
    else
    {
      word += ch;
    }
  }
  if (!word.empty())
  {
    words.push_back(word);
  }
}
Source Link
user246110
user246110

Here's another way of doing it..

void split_string(string text,vector<string>& words)
{
 int i=0;
 char ch;
 string word;

 while(ch=text[i++])
 {
  if (isspace(ch))
  {
   if (!word.empty())
   {
    words.push_back(word);
   }
   word = "";
  }
  else
  {
   word += ch;
  }
 }
 if (!word.empty())
 {
  words.push_back(word);
 }
}