2013-11-02 45 views
0

我有僅包含週期 (「」)矢量的矢量到目前爲止我想和我正在從輸入取入一個符號,以取代對電網某些座標文件。我正在使用替換方法,但不斷收到此錯誤在矢量的矢量替換元件C++

" error: no matching function for call to replace(std::basic_string, std::allocator >&, std::basic_string, std::allocator >&, const char [2], const char*)"

我不確定那個錯誤的含義。我感謝任何和所有的幫助。在這裏先謝謝

是我的代碼

#include <vector> 
#include <string> 
#include <fstream> 
#include <iostream> 
#include <algorithm> 



using namespace std; 

int main() 
{ 
string locationfilename, filenames,symbol; 
int numRows, numCols, startRow, startCol, endRow, endCol, possRow, possCol, id; 

cout<< "Enter Locations Filename"<<endl; 
cin>>locationfilename; 
cout<< "Enter Names Filename"<<endl; 
cin>>filenames; 

ifstream locations(locationfilename.c_str()); 
ifstream names(filenames.c_str()); 

locations>>numRows>>numCols>>startRow>>startCol>>endRow>>endCol; 

vector <string> rows(numCols,"."); 
vector< vector<string> > grid(numRows,rows); 


locations>>possRow>>possCol>>symbol>>id; 
while(!locations.fail()) 
{ 


    if(possRow>numRows || possCol>numCols) 
    { 
     cout<<id<< " out of bounds-ignoring"<<endl; 
    } 
    else 
    { 
    replace(grid.at(possRow).front(),grid.at(possRow).back(),".",symbol.c_str()); 
    } 

locations>>possRow>>possCol>>symbol>>id; 
} 

} 
+1

'的std :: replace'採取迭代器。 – chris

回答

1

正如指出的克里斯,你在std::replace傳遞的參數是不正確的。 std::replace預計iterators其前兩個參數,但你逝去的references

您可以使用begin()end()獲得迭代器:
std::replace(grid.at(possRow).begin(), grid.at(possRow).end(), ".", symbol.c_str());