// Example of peek() function #include using namespace std; int main() { cout << "Demonstrating example of peek() function\n"; int age; char firstName[21], temp; cout << "Enter first name and age (either order OK): "; temp = cin.peek(); // peek at first character if (temp >= '0' && temp <= '9') // if 1st character is a digit cin >> age >> firstName; // age is read first else cin >> firstName >> age; // name is read first cout << "\nResults:\n" << " First name = " << firstName << "\n Age = " << age << '\n'; return 0; }