Your code is so wrong it burns my eyes.
What is so wrong?
char *tmpLine = (char *)line.c_str();
First, you are (unless I'm wrong) casting away the constness of a std::string, which is a very bad idea. Anyway, casting away the constness smells of modification attempt...
t = strtok(tmpLine, "\t");
And here we are...
You are modifying the buffer provided by the std::string
, as strtok
destroys the string given to it.
Bad idea: You are not the owner of the std::string
's internal buffer, so you should not modify it (you don't want to break your string, and provoke a bug, want you?),
Back to the code:
t = strtok(tmpLine, "\t");
Ok, so, you're using strtok
, which is not a reentrant function.
I don't know what compiler you're using, but I guess most would have a more safe (i.e. less stupid) alternative. For example, Visual C++ provides strtok_s
. If you don't have one provided, then the best solution is to write your own strtok
, or use another tokenization API.
In fact, strtok
is one of the few counter-examples of "don't reinvent the wheel": In that case, rewriting your own will always be better than the original standard C function, if you have some experience in C or C++.
Ok, but, about the original problem?
Others have provided insight about alternatives, or even the fact the incomplete sample of code you provided seemed complete, so I'll stop here my analysis, and let you consider their answers.
I don't know what your code is for, but it is plain wrong, and would be even if the bug you reported (the missing token) didn't exist. Don't use that on production code.