I'm try to get input from a user using a templated function. I want to be able to input int, doubles, floats, and strings. So here's the code I have so far:
template<class DataType>
void getInput(string prompt, DataType& inputVar)
{
cout << prompt;
cin >> inputVar;
}
int main()
{
string s;
int i;
float f;
double d;
getInput("String: ", s);
getInput("Int: ", i);
getInput("Float: ", f);
getInput("Double: ", d);
cout << s << ' ' << i << ' ' << f << ' ' << d << endl;
return 0;
}
The basic types all work, but the problem I have lies with inputting string
s. I'd like to be able to input more than one word, but to the fact that I'm using cin I can't. So is it possible input multi-word strings as well the basic types in a manner similar to what I'm doing?