-1

I am trying to write a code that reads in a file and places it into a struct. However, when I run my code it gives me an unusual error and I cannot see anything wrong with my code.

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];
        }
}

The result show be a grid created from the information read in from the files/

) ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:313:5: note: declared private here ios_base(const ios_base&); // = delete; ^ /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd:131:32: note: implicit copy constructor for 'std::__1::basic_ios' first required here class _LIBCPP_TEMPLATE_VIS basic_ifstream; -->
Student
  • 11

1 Answers1

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

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

These two functions take ifstream by value. To pass the variable, it must be copied. However, ifstream's copy constructor is deleted.

Del
  • 1,309
  • 8
  • 21