I am new to C++, and new to programming altogether. I'm finishing up my first semester as a Computer Science major, but I'm struggling with programming.
I need to read a file into a 2D array.
Here is what the file contains (90 characters):
S
R
R
S
R
R
R
R
S
S
S
S
C
S
C
C
R
C
R
R
S
C
R
C
C
S
C
S
S
R
S
C
C
C
S
C
R
R
R
S
R
C
S
R
S
C
C
R
C
C
C
C
C
R
R
R
C
R
R
C
C
R
S
S
C
R
R
C
R
R
S
C
R
R
S
S
R
R
R
R
R
C
S
C
C
R
S
R
R
R
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
constint MONTHS = 3; //Number of months
constint DAYS = 30; //Number of days in each month
constint SIZE = 90; //Total number of days
void readFunction(char[], string[DAYS]); //readFunction prototype
int main()
{
char weatherArray[SIZE]; //Array for the weatherFile data
string summerArray[MONTHS][DAYS]; //Array for the 3 months and 30 days in each month
readFunction(weatherArray, summerArray);
return 0;
}
void readFunction(char weatherArray[], string summerArray[][DAYS]) //Reads weatherFile into summerArray
{
int row = 0, //Loop counter for rows
col = 0; //Loop counter for columns
ifstream weatherFile; //Weather file
for (row = 0; row < MONTHS; row++)
{
for (col = 0; col < DAYS; col++)
{
weatherFile.open("RainOrShine.dat");
summerArray[row][col] = weatherFile;
}
}
weatherFile.close();
}
Here is my list of errors: Error 1 error C2664: 'void readFunction(char [],std::string [])' : cannot convert argument 2 from 'std::string [3][30]' to 'std::string []' (line 17) Error 2 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::ifstream' (or there is no acceptable conversion) (line 33)
Could someone please explain to me what I'm doing wrong, and how to fix it?
Thank you in advance!
Okay, I fixed the first problem. I guess I just overlooked that. Thank you for pointing it out!
As for the second problem, I don't know how to read a file into a 2D array. I realize I cannot assign the 2D array into a character, but I don't know what to do.