This assignment I must read this .DAT file the instructor has given to me, and print out the information from it.

The .DAT file is for a two-way array
It has 6 rows and 8 colloumns

well I have ran into a couple of problems

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <iomanip>
#include <string>
using std::endl;
using std::setw;
#define clrscr() system("cls")
struct noiseLevel
{
short vehicleNo;
short noise[8];
};
void printArray(int[]);
noiseLevel noise;
int myCarArray[6][8];
int main(void)
{
int noise;
int row;
int col;
clrscr();
ifstream noiseFile ( "a:\\noise.dat", ios::in | ios::binary | ios::nocreate );
if (!noiseFile ) 
{
cout << "\nUnable to open NOISE.DAT";
cout << "\nPress any key to continue.....";
cin.get();
return 1;
}
 
/* Read and fill the array */
for (row = 0; row < 6; row++)
{
noiseFile.read ( reinterpret_cast<char *> (&noise), sizeof (noise)); 
 
for(col = 0; col < 8; col++)
{
myCarArray[row][col+1]=noise.noiseFile[col]; // left of .noiseFile must have class/struct/union type 
}
/* print it all out */
for (row = 0; row < 6; row++)
{
noiseFile.read ( reinterpret_cast<char *> (&noise), sizeof (noise)); 
 
for(col = 0; col < 6; col++)
{
cout << setw(5) << myCarArray[row][col]; // '<<': no operator defined which takes a right hand operand of type
cout << endl;
}

I have gotten two errors

I put the errors in comments next to code

Any help appreciated

Perhaps you meant to declare noise as a noiseLevel ? Then, the only thing wrong with this statement would be that you would need to use noise.noise, not noise.noiseFile:

myCarArray[row][col+1]=noise.noiseFile[col];
This article has been dead for over six months. Start a new discussion instead.