"How do you getline a float or integer?" Do you mean from a file? Well if you want to read data from a file you just use
1 2 3
ifstream read(randomnamehere);
......
read>>data;
Where ofcourse data is int or float. I don't know if this is what you need but please feel free to post your questions and I will try to help you. Happy coding : )
guestgulkan,
I copied this code from my projet and don't have to check whether input is number or not because *.dat file from which I read is created by the same program which writes ONLY numerical information out to the file.
If OP has problem with that then this is better one:
1 2 3 4 5 6 7
template <typename T>
inline T ToNumber(const string& text)
{
std::stringstream ss(text);
T result;
return ss >> result ? result : 0;
}
EDIT:
The same result and side behaviour is achived by using atoi function, but it is not template and works on integral values, and because OP asked for generics I gave him a template :)