Reputation: 93
I am getting the following error when using a getline() function:
no instance of overload function "getline" matches the argument list
In one class named "Time" I use it when reading in the following input:
istream & operator >> (istream & input, Time & C) /// An input stream for the hour minutes and seconds
{
char ch;
input >> C.hour >> ch >> C.minute >> ch >> C.second;
getline(input,C.ampm,',');
return input; /// Returning the input value
}
This works fine, but I also want to use it for another class called "Shares":
istream & operator >> (istream & input, Shares & C) /// An input stream for the day, month and year
{
char ch;
input >> C.price >> ch >> C.volume >> ch >> C.value >> ch;
getline(input,C.value,',');
return input; /// Returning the input value
}
However, the getline function in the "shares" class is giving me the error. Both classes are using the libraries:
#include <iostream>
#include <string>
How can I overcome this? Thanks
Upvotes: 2
Views: 9109
Reputation: 53173
getline(input,C.value,',');
based on the comments, you wrote that C.value
is double. That will not fly because as others pointed out, the expected parameter is a string type in there.
You would need to read into a temporary string and then convert it to your double. The latter step is simple, but even simpler with C++11's std::stod.
Therefore, you would be writing something like this:
std::string valueString;
getline(input, valueString, ',');
C.value = std::stod(valueString);
Upvotes: 2