0

到目前为止,我有一个仅包含句点(“。”)的向量,我想用从输入文件中获取的符号替换网格上的某些坐标。我正在使用替换方法,但不断收到此错误

“错误:没有用于调用替换的匹配函数(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;
}

}
4

1 回答 1

1

正如克里斯所指出的,您传入的参数std::replace不是正确的。std::replace期望iterators它的前两个参数,但您正在传递references.

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

于 2013-11-03T00:09:20.520 回答