Beispiel #1
0
/**
 * 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;
}
Beispiel #2
0
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;
}