Reputation: 27
For some reason getline will not work with a double and it gives me a message saying "getline no instance of overloaded function "getline" matches the argument list argument types are: (std::istream, double)" if I change the doubles to strings it works so I am unsure what the problem is, if anyone could help it would be much appreciated
Upvotes: 0
Views: 11899
Reputation: 15
The problem occurs because getline()
reads only strings. To read a double, you must use cin
.
Upvotes: -1
Reputation: 409196
That's because std::getline
is for reading strings. And only strings. If you want to get a floating point value read it as a string and convert to a floating point value. Or use the input operator >>
.
Upvotes: 3
Reputation: 206607
Use
cin >> athOneTime;
to extract a double
. If you want to skip the rest of the line, use
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
Upvotes: 1