使用getline()函数时出现以下错误:
没有重载函数“ getline”的实例与参数列表匹配
在一个名为“时间”的类中,当读取以下输入时,将使用它:
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
}
这可以正常工作,但我也想将其用于另一个名为“ 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
}
但是,“ shares”类中的getline函数给了我错误。这两个类都在使用这些库:
#include <iostream>
#include <string>
我该如何克服呢?谢谢
getline(input,C.value,',');
根据评论,您写道这C.value
是双重的。这不会奏效,因为正如其他人指出的那样,期望的参数是其中的字符串类型。
您将需要读入一个临时字符串,然后将其转换为您的double。后面的步骤很简单,但是使用C ++ 11的std :: stod甚至更简单。
因此,您将编写如下内容:
std::string valueString;
getline(input, valueString, ',');
C.value = std::stod(valueString);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句