2014-12-19 3 views
0

텍스트 파일을 읽고 인수로 참조되는 벡터를 채우는 함수가 있습니다.C++ 다시 그려진 벡터에 데이터를 반환하는 함수

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();*/ 



}    
+3

당신이하려고하는가의''벡터 '에'벡터 을'push_back'해야

vector<double*> &vect 

것 같은데? 네가 뭘하려고하는지 모르겠다. – CoryKramer

+0

@RomanKhutoretsky : 당신이'벡터 '대신'벡터 <벡터 >'을 찾고 있다고 생각합니다. –

+0

그래서 내 프로그램에서 벡터 2D 벡터를 만들었습니다. 이 함수를 사용하여 텍스트 파일을 읽는 중 벡터를 채 웁니다. 벡터 TempArray를 만들었습니다. 각 쉼표 (또는 다른 기호) 구분선을 읽고 각 요소를 내 TempArray에 할당합니다. 그래서 그것은 내 마지막 벡터의 1 행을 가져야합니다. 마지막 벡터가 필요한 모든 데이터를 가진 2 차원 배열이되도록 각 행을 읽는 것을 마치면서이 벡터를 최종 출력 벡터 (vect)로 푸시하고 싶습니다. –

답변

1

vector<vector<double>> &vect 
+0

정확히 내가 필요로했던 것! !!!! 고마워요 얘들 아. –