| | |
Read data from a two-way array from a .DAT file?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 8
Reputation:
Solved Threads: 0
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
I have gotten two errors
I put the errors in comments next to code
Any help appreciated
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
C++ Syntax (Toggle Plain Text)
#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
Last edited by youngone; Apr 19th, 2007 at 11:09 pm.
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: C++ Syntax (Toggle Plain Text)
myCarArray[row][col+1]=noise.noiseFile[col];
"Technological progress is like an axe in the hands of a pathological criminal."
![]() |
Similar Threads
- Reading .dat file data into an array (C#)
- Setting an array and reading in a txt file backwards (C++)
- help me to read my data file:(( (C)
- read data from file (C++)
- Making a .dat file (C++)
- read a dat file through C (C)
Other Threads in the C++ Forum
- Previous Thread: c++ with graphics
- Next Thread: Hi
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






