gpt4 book ai didi

c++函数,它将数据返回到引用 vector

转载 作者:行者123 更新时间:2023-11-28 06:31:03 24 4
gpt4 key购买 nike

我有一个读取文本文件并填充作为参数引用的 vector 的函数。

vect.push_back(TempArray); 

是导致我出错的行。有什么想法吗?

Error   1   error C2664: 'void std::vector<_Ty>::push_back(double *&&)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'double *&&'    d:\aul_c++_12102014\aul_c++_rk_version_12182014\aul\aul\projection.h    206 1   AUL

int projection::import_inputTables(string input_file, string output_file, int dimen, vector<double*> &vect, long col_filler, long row_filler, string delim, int OptArgVar)
{

long i=0,j=0,k=0;

int total_Col = dimen;
long MaxLinesNum = 100000;
const string DELIM = delim;
string Line;
string LineCell;
long LineCounter = 0;
long LinesRead = 0;
int LineReadPoint = 0;

//Determines number of lines to be read
if (OptArgVar == 0) //Read untill the end
{
MaxLinesNum = 100000;
}
else if (OptArgVar == 1)
{
MaxLinesNum = 1;
}
else if (OptArgVar == 2)
{
MaxLinesNum = 51;
}

ifstream input_stream;
input_stream.open(input_file);

if (input_stream.is_open())
{
while( MaxLinesNum > LinesRead )
{
getline(input_stream,Line);
if (LineCounter >= col_filler)
{
vector<double> TempArray;

for (j = 0; (j < total_Col); j++) //Column Loop
{
LineCell = Line.substr(0,Line.find(DELIM));
Line.erase(0,Line.find(DELIM) + DELIM.length());

TempArray.push_back(stod(LineCell));

}

vect.push_back(TempArray);
vector<double> ().swap(TempArray);

LinesRead++;
LineCounter++;
}
else
{
LineCounter++;
}

if (MaxLinesNum == LinesRead) //Read only the needed number of lines --- Will read entire file if OptArgVar is set to 0
break;
}
}
else
{
cout << "Could Not Open File" << endl;
}

//PRINT STATEMENT DO NOT DELETE
input_stream.close();

return vect.size();

/*ofstream out(output_file);
out.precision(10);
for (j = 0; j < vect.size(); j++){
for (i = 0; i <= total_Col; i++){
out << vect.at(j)[i]<< '\t';
}
out << '\n';
}
out.close();*/



}

最佳答案

看起来像

vector<double*> &vect

应该是

vector<vector<double>> &vect

关于c++函数,它将数据返回到引用 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27571259/

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