没有用于初始化< ifstream'的匹配构造函数

时间:2017-12-10 22:08:12

标签: c++ struct constructor ifstream

我正在尝试编写一个读取文件并将其放入结构中的代码。但是,当我运行我的代码时,它给了我一个不寻常的错误,我看不出我的代码有什么问题。

struct Map    {

int x;
int y;
char symbol;
int id;
string fullname;
bool visited;
}; 

void locationFile(ifstream filename, vector<Map> &vmap, int rows, int 
col) 

{
Map map;

while (filename >> map.x >> map.y >> map.symbol >> map.id)
{
    if (map.x> rows || map.x< 1 || map.y> col || map.y<1)
    {
        cout << map.id << " out of range -  ignoring" << endl;
        map.visited = true;
    }
    else
    {
        vmap.push_back(map);
    }
}
}

void namesFile(ifstream names, vector<Map>& vmap)
{
Map map;

while(names >> map.id>> map.symbol)
{
    vmap.push_back(map);
}
}

int main()
{
vector<Map> info;
string location;
string names;
getFilenames(location, names);

//open files
ifstream inL;
inL.open(location.c_str());

string journey= "journey.txt";
ofstream fout(journey.c_str());

int rows, col, sx, sy, ex, ey;
inL >> rows >> col >> sx >> sy >> ex >> ey;

locationFile(inL, info, rows, col);

inL.close();

ifstream inN;
inN.open(names.c_str());
namesFile(inN, info);
inN.close();



vector< vector<string> > grid;
grid= createGrid(info, rows, col, sx, sy, ex, ey);

//print out grid
for(int h=0; h< grid.size(); h++)
{
    for(int g=0; g<grid.size(); g++)
        {
            fout << grid[h][g];
        }
}

结果显示是根据从文件/

读入的信息创建的网格 )                                                                ^ / Library / Developer / CommandLineTools / usr / include / c ++ / v1 / ios:313:5:注意:       在这里宣布私有     ios_base(const ios_base&amp;); // =删除;     ^ / Library / Developer / CommandLineTools / usr / include / c ++ / v1 / iosfwd:131:32:注意:       &#39; std :: __ 1 :: basic_ios&#39;的隐式复制构造函数首先需要       这里     class _LIBCPP_TEMPLATE_VIS basic_ifstream; - &GT;

1 个答案:

答案 0 :(得分:0)

void locationFile(ifstream filename, vector<Map> &vmap, int rows, int col)

void namesFile(ifstream names, vector<Map>& vmap)

这两个函数按值ifstream取值。要传递变量,必须复制它。但是,ifstream's copy constructor is deleted