私は C++ が初めてで、入力のトークン化に取り組んでいます。コメント行 "cout<< "p: " << p << endl;" 2 番目の関数呼び出しが実行されないのはなぜですか?
#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;
}