Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#ifndef INPUTTEST_H
#define INPUTTEST_H
#include<iostream>
#include<string>
#include<sstream>
#include <limits>
/**
* This function is adapted from the code provided to us in 4003CEM, as a way to validate the type of input from the player.
*/
template<typename T>
T inputTest( std::string prompt="" )
{
while(true)
{
if( !prompt.empty() )
std::cout << prompt;
T value;
std::cin >> value;
if( std::cin.fail() )
{
std::cin.clear();
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
std::cout<<"The input was incorrect. Try a different one.";
continue;
}
return value;
}
}
#endif