string::c_str
const char* c_str() const noexcept;
功能:返回c风格字符转
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string s1("i love lyy, i want marry with her");
char *pp = new char[s1.length() + 1];
strcpy(pp, s1.c_str());
char *p = strtok(pp, " ");
while(p)
{
cout << p << endl;
p = strtok(NULL, " ");
}
delete[] pp;
return 0;
}