我是 C++ 新手,我正在对输入进行标记。注释行 "cout<< "p: " << p << endl;" 使第二个函数调用不执行,为什么?
#include <iostream>
#include <string>
#include <string.h> //for library strtok()
#include <sstream> //for useStringStream()
using namespace std;
void useStrTok(){
char myString[] = "The quick brown fox";
char *p = strtok(myString, " ");
while (p) {
cout<< "token: " << p<< endl;
p = strtok(NULL, " ");
//cout<< "p: " << p << endl;
}
}
void useStringStream(){
string myText("The quick brown fox");
istringstream iss(myText);
string token;
while(getline(iss,token, ' '))
{
cout << token << endl;
}
}
int main(){
useStrTok();
useStringStream();
return 0;
}