Answers for "c++ get input without loop"

C++
1

c++ get input without loop

#include <iostream>

int receive(void)
{
  	int input;
	if (!(std::cin >> input))
    {
      // TODO: If input is unvalid
      // Clear error flag
      std::cin.clear();
      // Remove incorrect data from buffer
      std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    }
 	return input; 
}
Posted by: Guest on December-12-2020

Browse Popular Code Answers by Language