I’m trying to write a complex tic tac toe game by using a multidimensional array. This is a piece of code that’s supposed to print this:
g | g | g
----------
g | g | g
----------
g | g | g
Where g is multidimensional array from g[1][1] to g [3][3] where g[3][3] is a string. The program bellow is supposed to print the first row from the board above.
#include <iostream>
#include <string>
using namespace std;
int main() {
string g[3][3];
g[1][1] = " ";
g[2][1] = " ";
g[3][1] = " ";
g[1][2] = " ";
g[2][2] = " ";
g[3][2] = " ";
g[1][3] = " ";
g[2][3] = " ";
g[3][3] = " ";
cout << " " << g[1][1] << " " << "|" << " " << g[2][1] << " " << "|" << " " << g[3][1];
cout << "----------------";
}
Upon running this program above a console opens and I get an unhandled win32 exception occured in “TESTIFICATE.exe” [2812]. I get a window where I’m supposed to select a debugger. When choosing a compiler Visual studio 2010 opens and I get some weird header files in front of me.
Note that the above program is a portion of the main program which worked swell until I added that piece of code, from which I got the unhandled win32 exception message. This has never happened to me in a program before and this isn’t supposed to be happening since the program is relatively simple.
Additional details:
- OS: Windows XP professional SP3;
- I have Visual studio 2010 installed (Not the express edition)
- I’m using Codeblocks IDE;
- Upon compilation I get no warnings or errors in my IDE.
If any further details are needed post in comments and I will post them.
Array indexes start from
0sog[3][3]is invalid memory access.