/** * logics: import, declare, init a token string, ... * patt: iterator for items */ void countTokens() { Scanner scanner; // uppercamelcase for Class cout << "Enter a sentence as a token string: "; scanner.setInput(getLine()); // scanner.setInput(string str) while(scanner.hasMoreToken()) { // bool scanner.hasMoretoken() cout << scanner.nextToken() << " "; // string scanner.nextToken() } cout << endl; }
void countTokens() { Scanner scanner; cout << "Input a setence:"; scanner.setInput(GetLine()); int count = 0; while (scanner.hasMoreTikens()) { scanner.netToken(); count++; } cout << "you entered" << cout << "token" << endl; }