gpt4 book ai didi

c++ - vector 被转换为 vector>

转载 作者:行者123 更新时间:2023-11-27 23:17:38 31 4
gpt4 key购买 nike

我正在创建一个 double vector ,然后尝试将其添加到我定义的对象中。问题是我的 vector<double>正在转换为 vector<double, allocator<double>>不知何故。谁能看出原因?

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

double stringToDouble( const std::string& s )
{
std::istringstream i(s);
double x;
if (!(i >> x))
return 0;
return x;
}

int main() {
ifstream userDefine("userDefine.csv");
string token, line;
stringstream iss;
int count = 0;
vector<double> prices;

while ( getline(userDefine, line) )
{
iss << line;
while ( getline(iss, token, ',') )
{
double temp = stringToDouble(token);
prices.push_back(temp);
}
}
return 0;
}

然后在添加到我的对象时出现以下错误:

no matching function for call to generatorTemplate::generatorTemplate(std::string&, std::vector<double, std::allocator<double> >&......

最佳答案

std::vector<T>实际上是 template < class T, class Alloc = allocator<T> > class vector; .如您所见,它具有带默认值的分配器类型参数。您正在观察的是预期的。这没有错。

关于c++ - vector<double> 被转换为 vector<double, allocator<double>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15459971/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com