先上测试代码
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { const char* split = ";"; char* str = "Hello;world;"; //result = NULL; char* result = strtok(str, split); cout << result; cin.get(); return 0; }
运行后
strtok函数在运行时,报堆栈读写冲突问题,后来看到strtok.c源文件里面对字符串的操作如下
/* Find the end of the token. If it is not the end of the string, * put a null there. */ for ( ; *str ; str++ ) if ( map[*str >> 3] & (1 << (*str & 7)) ) { *str++ = '