C++ getline() 错误,没有与参数列表匹配的重载函数"getline"实例
c++ getline() error, no instance of overload function "getline" matches the argument list
使用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
}
这很好用,但我也想把它用于另一个名为"股票"的类:
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
是双的。这不会成功,因为正如其他人所指出的,预期的参数是其中的字符串类型。
您需要读入一个临时字符串,然后将其转换为双精度字符串。后一个步骤很简单,但使用C++11的std::stod更简单。
因此,你会写这样的东西:
std::string valueString;
getline(input, valueString, ',');
C.value = std::stod(valueString);
相关文章:
- getline 函数似乎在 C++ 中不起作用
- 如何以及何时使用 getline 函数执行计算?
- 对c++中的输入使用getline函数时忽略第一个字符
- 使用 c++ 中的 getline 函数连续读取两行
- 此C Getline函数的C 代码有什么问题
- 使用 getline 函数读取文件,但第一列显示为空
- 使用 getline 函数获取分段错误
- getline函数只读取第一行
- c++getline函数不允许我输入
- 使用getline函数时出现问题
- 如何正确使用标准::getline函数
- C++:将带有空格的cin转换为不带getline函数的字符串
- 而循环构造与 getline 函数相结合,一直持续到 EOF
- 使用 getline 函数的最优雅方式
- 使用 getline 函数解析 C++ 中的字符串
- 我们如何在程序中同时使用 cin 和 getline 函数
- std::getline函数(fstream _Lock())出错
- 验证输入和getline()函数
- **编译器错误** - getline() 函数不接受第一个参数"std:ifstream"是什么我的问题?
- c++中的Getline()函数需要少一个输入