Hi, I am reading from a text file and stored it onto a string variable. Now I want to split the string and I tried looking it up on the web and found the strtok () function but that only works on a char type.
Here is my code snippet:

#include <iostream>
#include "Stack.h"
#include <string.h>
#include <fstream>
using namespace std;

int main()
 Stack list;
 ifstream ReadFrom;
 string line;

(getline(ReadFrom, line));
split = strtok(line.c_str(),",.( )") // this does not work.;

Can some one give me an idea on how to accomplish this. Note: variable line has to be string type unless there is another way to read whole line from a text file.


Here is a good tutorial on using strtok(), it's written in C, but that's what you get for using c-strings teehee

it offers this example:

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
  char str[] ="- This, a sample string.";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str," ,.-");
  while (pch != NULL)
    printf ("%s\n",pch);
    pch = strtok (NULL, " ,.-");
  return 0;

Here is my first attempt at strtok()'ing: