I am creating a battleship game using c++, we have to load text files which contain the user's guesses & another file which contains the boat locations. I am approaching this by loading the data from the files into a 2D array. The goal is to be able to compare the two 2D arrays in order to determine if the user has won the game. I am struggling with loading the data into the array. This is my code for inputting the Users guess file.
#include "stdafx.h"
#include "openconfigfile.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void openconfigfile()
{
int row = 12;
//Open the file in the location specified by user
ifstream file("C: Project Files\\Proj01_files\\in1.txt");
//Check that the file was opened & loaded into array
if (file.is_open())
{
cout << "User input file has been loaded." << endl;
string inputarray[12][2];
while (file.good()) {
for (int col = 0; col < 2; col++) {
file >> inputarray[12][2];
}
row++;
}
}
else cout << "Unable to open user input file.Please check your file path is correct.";
file.close();
}
I know there is something wrong with the while loop since every time I run the project it tells me that my project file has stopped working. I am not sure how to fix it. Any help would be appreciated.