M.Stran94
M.Stran94

Reputation: 27

C++ getline not working with double

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

Answers (3)

JMBCODE
JMBCODE

Reputation: 15

The problem occurs because getline() reads only strings. To read a double, you must use cin.

Upvotes: -1

Some programmer dude
Some programmer dude

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

R Sahu
R Sahu

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

Related Questions