I'm trying to read some input from a file and print it. I have three files: Main.cpp Sudoku.cpp Sudoku.h.
For some reason the program will not print anything unless it's in the main function. If I print anything in one of the functions of Sudoku.cpp file and the use that function in the program, it will not print.
EDIT: I figured out the problem is in the "Load" function. Can anyone tell me what I did wrong there? It seems to freeze once it reaches that.
Main.cpp:
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "hello" << endl; //"hello" actually prints; nothing else does
Sudoku MyPuzzle;
MyPuzzle.Load();
MyPuzzle.Print();
return 0;
}
Sudoku.h
#ifndef SUDOKU_H
#define SUDOKU_H
#include "StdAfx.h"
class Sudoku
{
public:
void Load();
void Print();
private:
int Puzzle[9][9];
};
#endif
Sudoku.cpp
#include "stdafx.h"
using namespace std;
void Sudoku::Load() { //something wrong here
ifstream fp_in("Project4_input1.in", ios::in);
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
cin >> Puzzle[i][j];
}
}
cout << "Loaded all values."<< endl;
fp_in.close();
}
void Sudoku::Print() {
for(int i=0; i<9; i++){
for(int j=0; j<9; j++){
cout << Puzzle[i][j] << " ";
}
cout << endl;
}
}
So when I compile the headers, build the project and run Main.exe I just get "hello". Nothing else is being written.
Maybe this is just something really simple that I'm not seeing.
Any help is greatly appreciated
Thank you