Sudoku solver - Stack overflow.

I am a complete beginner at C++ and I have been tasked to create a sudoku solver, I have written a partial sudoku solver but when I try to compile, I get a stack overflow error.

Any help is appreciated, thanks.
Last edited on
Are you using a C++98 or C++11 compiler? C++98 doesn't accept a string as an argument to open (lines 27, 51). Use filename.c_str() instead.

When you say you get a stack overflow, are you referring to the compiler, or to the execution of your program? Stack overflows in the compiler are rare.
I think the stack overflow is on the execution of my program.
Stack overflow occurs with recursion (line 176) when you recurse too deeply, or don't have a proper check for a termination condition.

Be aware that your local variables (including your vector) are going to be pushed on to the stack with every nested call.
Hmm thanks, any tips on what I can do to stop this from happening?
Don't recurse so deeply. :)

Seriously, try and reduce the amount of data you're pushing onto the stack.
Try and eliminate lines 112-115. Perhaps create a struct for these items and push that struct onto a global std::stack each time you enter a level, and popping that stack when you exit out of a level. You're much more likely to be able to have enough storage for the maximum depth of your recursion using the heap instead of the stack.
Topic archived. No new replies allowed.