This my first post on stackoverflow so hopefully what I have posted adheres to correct guidelines/format on this forum site.
I am new to C++ so please bear with me. I am trying to implement a sudoku solver in C++ and 1 of my objectives is to read in a sudoku puzzle which is 9x9 grid, into an object array, specifically a 2D array and then display it's contents onto the command window.
The sudoku puzzle given is in the following format:
0 3 0 0 0 1 0 7 0
6 0 0 8 0 0 0 0 2
0 0 1 0 4 0 5 0 0
0 7 0 0 0 2 0 4 0
2 0 0 0 9 0 0 0 6
0 4 0 3 0 0 0 1 0
0 0 5 0 3 0 4 0 0
1 0 0 0 0 6 0 0 5
0 2 0 1 0 0 0 3 0
What I have in my header file (sudoku_header.h) is the following:
#pragma once
#ifndef SUDOKU_HEADER
#define SUDOKU_HEADER
#include <vector>
using namespace std;
class Cell
{
public:
friend istream& operator >>(istream &input, Cell& cellObject);
friend ostream& operator <<(ostream &output, Cell& cellObject);
bool ValueGiven();
void AssignCell(int num); // assigns a number to a cell on the puzzle board
void PopulateRows();
private:
int row, column, block; // triple context i.e. row, column and block
vector<int> candidateList; // holds a vector of all the possible candidates for a given cell
};
istream& operator >>(istream& input, Cell& cellObject)
{
input >> cellObject.row;
input >> cellObject.column;
return input;
}
ostream& operator <<(ostream& output, Cell& cellObject)
{
output << cellObject;
return output;
}
#endif
and this is whats inside my main.cpp file:
#include <iostream>
#include <fstream>
#include <ostream>
#include <istream>
#include "sudoku_header.h"
void PopulateRows(string filename)
{
Cell **cellObject;
const int row = 9;
const int column = 9;
cellObject = new Cell*[9];
for (int i = 0; i < 9; ++i)
{
cellObject[i] = new Cell[9];
for (int j = 0; j < 9; ++j)
{
cout << &cellObject[i][j] << endl;
}
}
}
int main()
{
PopulateRows("sudoku_puzzle.txt");
cout << "\n\nPlease enter a key to exit..." << endl;
cin.get();
return 0;
}
Now the above code will compile and work and will display the memory addresses for each of the cellObjects, but I want to be able to read in a sudoku puzzle, named "sudoku_puzzle.txt" and then display its contents in a 9x9 grid fashion.
Can anyone possibly point me in the right direction or even show me how?