I am parsing one tab delimited file with some missing values. When i use the strtok function, I can not get the values based on index in vector. The code shown below explains my pblm.
Expand|Select|Wrap|Line Numbers
- #include <iostream.h>
- #include <string.h>
- #include <vector.h>
- using namespace std;
- int main ()
- {
- char str[] ="XYZ 2 a sample data";
- char * pch;
- vector <char*> vec;
- pch = strtok (str,"\t");
- while (pch != NULL)
- {
- vec.push_back(pch);
- pch = strtok (NULL, "\t");
- }
- cout << "Fifth null element is "<<vec[4]<<"\n";
- return 0;
- }
Thansk in advance.