Skip to content

Instantly share code, notes, and snippets.

@denniskupec
Created June 10, 2017 04:53
Show Gist options
  • Save denniskupec/13bb0a6f729d4f1d9a75a99ad05a4879 to your computer and use it in GitHub Desktop.
Save denniskupec/13bb0a6f729d4f1d9a75a99ad05a4879 to your computer and use it in GitHub Desktop.
/* 2017 Dennis Kupec | MIT License */
#include <iostream>
#include <functional>
#include <string>
#define Str(s) std::to_string(s)
using namespace std;
template <typename T> T get_input(const string msg);
template <typename T> T get_input(const string msg, function<bool(string)> verify);
template <typename T> T get_input(const string msg)
{
T in;
do {
cout << msg;
getline(cin, in);
}
while (cin.fail());
return in;
}
template <typename T> T get_input(const string msg, function<bool(string)> verify)
{
T in;
do {
cout << msg;
getline(cin, in);
}
while (cin.fail() || !verify(in));
return in;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment