我有一个函数,它读取一个文本文件并填充一个被引用为参数的向量。
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();*/
}
答案 0 :(得分:1)
看起来像
vector<double*> &vect
应该是
vector<vector<double>> &vect