从有效文件读取时,没有对应的错误调用函数
No matching function for call to error when reading from a valid file
我在一个文件中有以下数据:
0001 O 100 102.30
0001 O 101 333.22
0001 O 102 679.13
0001 P 103 513.36
0001 P 104 700.94
,代码如下:
vector<string> customerID;
vector<char> transactionType;
vector<string> transactionNumber;
vector<double> amount;
string cID, tT, tN, amnt;
for(;infile2 >> cID >> tT >> tN >> amnt;){
customerID.push_back(cID);
transactionType.push_back(tT);
transactionNumber.push_back(tN);
amount.push_back(amnt);
}
和错误:
error: no matching function for call to 'std::vector<char>::push_back(std::string&)'
error: no matching function for call to 'std::vector<double>::push_back(std::string&)'
是否假设每个数据项都是字符串?
是的。你正在读取四个字符串,你正在将它们中的任何一个转换成其他任何东西。c++不提供从std::string
到非字符串类型的隐式转换。
解决问题的最简单方法是将tT
和amnt
读取为char
和double
。只需将变量声明为
std::string cID, tN;
char tT;
double amnt;
,它应该可以工作。或者,您可以将它们作为字符串读取并转换。
如上所述,您在读取时使用了四个string
变量。您可以通过声明适当类型的变量来纠正它。
vector<string> customerID;
vector<char> transactionType;
vector<string> transactionNumber;
vector<double> amount;
string cID, tN;
char tT;
double amnt;
for(;infile2 >> cID >> tT >> tN >> amnt;){
customerID.push_back(cID);
transactionType.push_back(tT);
transactionNumber.push_back(tN);
amount.push_back(amnt);
}
相关文章:
- 链接器错误:函数的多个定义
- 编译器错误:函数调用在常量表达式中必须有一个常量值
- 错误:函数声明符之后的预期函数体
- C 错误 - 函数不能超载
- 如何修复传递参数时调用错误函数的主函数?(C++)
- 错误:函数调用中有两个参数
- 错误:函数不是“类”的静态数据成员 - C++
- C ,G 编译错误函数
- CMake 解析错误函数缺少结尾")"。而是找到带有文本的未终止字符串")
- C++ 错误 函数 2 的多重定义
- 错误:函数调用中从int到int(*)[4]的转换无效
- C++14 自动扣除错误:函数返回一个数组
- 视觉C++错误:函数必须返回一个值
- 错误:函数声明中的两种或多种数据类型
- 错误:函数未在作用域中声明
- rtw_android.c错误:函数“strnicmp”的隐式声明[-Weror=隐式函数声明]
- 错误:函数中的return语句没有值,返回“void*”[-fpermission]
- 简单程序中的链接器错误:函数的多重定义
- 错误:函数参数太多
- 错误:函数__tmaincrtstartup中引用的未解析的外部符号_main