Here is the code snippet
Expand|Select|Wrap|Line Numbers
- #include "Block.h"
- #include "Solver.h"
- #include <iostream>
- #include <istream>
- #include <ostream>
- #include <fstream>
- using namespace std;
- int main( int argc, char* argv[]) {
- if(argc != 3) {
- cerr << "Usage: \"block input-file\" \"output-file" << endl;
- exit(-1);
- }
- //streams
- istream *isp;
- ifstream ifs;
- ostream *osp;
- ofstream ofs;
- if (argv[1][0] == '-' && argv[1][1] == '\0') {
- isp = &cin;
- } else {
- ifs.open(argv[1]);
- isp = &ifs;
- }
- istream &is = *isp;
- if (argv[2][0] == '-' && argv[2][1] == '\0') {
- osp = &cout;
- } else {
- ofs.open(argv[2]);
- osp = &ofs;
- }
- ostream &os = *osp;
- //GET INFO ON THE PUZZLE
- //get rows and cols
- int rows;
- int cols;
- is >> cols >> rows;
- // get starting puzzle into array
- vector<int> starting;
- vector<int> ending;
- char temp;
- int counter = 0;
- //cout << rows << "" << cols << endl; ----ERROR OCCURS AT THIS LINE IF I DO NOT COMMENT IT.
- while(is.good() && counter < (rows*cols)){
- is >> temp; --------ERROR OCCURS AT THIS LINE
- starting.push_back((int)temp);
- counter++;
- }
- // get solution puzzle into array
- counter = 0;
- //int t=rows*cols;
- while(is.good() && counter < (rows*cols)){
- is >> temp;
- ending.push_back((int)temp);
- counter++;
- }
- Block ll(os, starting, ending, rows, cols);
- Solver s(ll);
- ll.display(s.solve(starting));
- };