阅读背景:

使用strtok拼接cstrings,仅适用于首次执行循环

来源:互联网 

I am trying to use strtok to splice a line read into a cstring into individual strings. Yes I know this could be done much more easily with string objects, but I'm not allowed to use them. When this code executes it works perfectly on the first line, then it continues to only work on that same line for every iteration of the loop. The file is being successfully read into the 'line' char array veriable, as evidenced by cout << line << endl; However strtok and the second while loop continue to split the first line read in every single time. Each line contains a first_name last_name ID and six grades. I guess I will just rewrite it and have getline delimit at white space and read in individual strings, but does anyone know why strtok is only splicing the first string on each successive iteration of the loop? I am trying to use strtok to splice a line read




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: