jeudi 4 juillet 2019

Unable to read text file with boolean grid into vectors of vectors

I have a text file which consists of boolean grid like structure as shown.Now,I am trying to read the text file into vector>grid.But I am unable to do so.My code is exiting without any error and execution also not moving inside while loop.Any help is highly appreciated! Text file has below sample:

00000000000000001111111110000 000000100000000010100000100 0000000000000000111111111000 00000000000000011111111111000 0001000000000011111111111110 00000000000000011000000011000 00000000000000100010001000100 00000000000000100000100000 00100011111111111111111001110 00000000000011111000100000001

  #include <iostream>
  #include <fstream>
  #include <vector>
  #include <string>
  #include <sstream>
  using namespace std;

   vector<vector<bool> >read_grid(const string &filename)
   {
      vector<vector<bool> > gridvector;
      // Open the File
      ifstream in(filename.c_str());
      string str;
      bool tempb;// Check if object is valid
      if(!in)
        {
         cout<< "Cannot open the File : "<<filename<<endl;
         return gridvector;
        }

         // Read the next line from File untill it reaches the end.
         while (getline(in, str))
        {
          istringstream iss(str);
          vector<bool> myvector;
         while(iss>>tempb)
         {
           myvector.push_back(tempb);
         }
            gridvector.push_back(myvector);
        }
          //Close The File
          in.close();
          return gridvector;

    }

  int main ()
   {
     const string b_file = "intial_grid.txt";
     vector< vector<bool> > grid_copy = read_grid(b_file);
     display_grid(grid_copy);
     return 0;
    }

It is exiting with 'exit status -1'

Aucun commentaire:

Enregistrer un commentaire