Read data from a two-way array from a .DAT file?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2007
Posts: 8
Reputation: youngone is an unknown quantity at this point 
Solved Threads: 0
youngone youngone is offline Offline
Newbie Poster

Read data from a two-way array from a .DAT file?

 
0
  #1
Apr 19th, 2007
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

  1. #include <iostream.h>
  2. #include <fstream.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <iomanip>
  6. #include <string>
  7. using std::endl;
  8. using std::setw;
  9. #define clrscr() system("cls")
  10. struct noiseLevel
  11. {
  12. short vehicleNo;
  13. short noise[8];
  14. };
  15. void printArray(int[]);
  16. noiseLevel noise;
  17. int myCarArray[6][8];
  18. int main(void)
  19. {
  20. int noise;
  21. int row;
  22. int col;
  23. clrscr();
  24. ifstream noiseFile ( "a:\\noise.dat", ios::in | ios::binary | ios::nocreate );
  25. if (!noiseFile )
  26. {
  27. cout << "\nUnable to open NOISE.DAT";
  28. cout << "\nPress any key to continue.....";
  29. cin.get();
  30. return 1;
  31. }
  32.  
  33. /* Read and fill the array */
  34. for (row = 0; row < 6; row++)
  35. {
  36. noiseFile.read ( reinterpret_cast<char *> (&noise), sizeof (noise));
  37.  
  38. for(col = 0; col < 8; col++)
  39. {
  40. myCarArray[row][col+1]=noise.noiseFile[col]; // left of .noiseFile must have class/struct/union type
  41. }
  42. /* print it all out */
  43. for (row = 0; row < 6; row++)
  44. {
  45. noiseFile.read ( reinterpret_cast<char *> (&noise), sizeof (noise));
  46.  
  47. for(col = 0; col < 6; col++)
  48. {
  49. cout << setw(5) << myCarArray[row][col]; // '<<': no operator defined which takes a right hand operand of type
  50. cout << endl;
  51. }

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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: Read data from a two-way array from a .DAT file?

 
0
  #2
Apr 19th, 2007
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:
  1. myCarArray[row][col+1]=noise.noiseFile[col];
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC