Check out example codes for "peak in c++". It will help you in understanding the concepts better.

Code Example 1

// istream::peek example
#include <iostream>     // std::cin, std::cout
#include <string>       // std::string
#include <cctype>       // std::isdigit

int main () {

  std::cout << "Please, enter a number or a word: ";
  std::cout.flush();    // ensure output is written

  std::cin >> std::ws;  // eat up any leading white spaces
  int c = std::cin.peek();  // peek character

  if ( c == EOF ) return 1;
  if ( std::isdigit(c) )
  {
    int n;
    std::cin >> n;
    std::cout << "You entered the number: " << n << '\n';
  }
  else
  {
    std::string str;
    std::cin >> str;
    std::cout << "You entered the word: " << str << '\n';
  }

  return 0;
}

Learn ReactJs, React Native from akashmittal.com