943,983 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 29151
  • C++ RSS
Nov 1st, 2005
0

Making a .dat file

Expand Post »
I need to write a program, in C++, that will read from a .dat file

How do I make one? My book mentions a header line, etc. It does not go into any more detail and I can't find a description of how to do it online.

Am I making this harder than I need to?

Thanks,
MB1
Similar Threads
mb1
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mb1 is offline Offline
7 posts
since Mar 2005
Nov 1st, 2005
0

Re: Making a .dat file

Show us your basic attempt start to the code with [code][/code] tags.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 1st, 2005
0

Re: Making a .dat file

All I can figure is to make a .txt file and call it Scores.dat

In the file:

C++ Syntax (Toggle Plain Text)
  1. Names Score1 Score2 Score3 Score4 Score5
  2. Sims 91 89 73 81 93


I'm supposed to read from the .dat file and compute the scores and assign a letter grade. I've got the program but I have no idea on where to start to make a .dat file.
Thanks for getting back with me.
Last edited by mb1; Nov 1st, 2005 at 4:05 pm. Reason: Arrange information
mb1
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mb1 is offline Offline
7 posts
since Mar 2005
Nov 1st, 2005
0

Re: Making a .dat file

Quote ...
I've got the program
You've got a program that reads from the .dat file, so why not post that?
Quote ...
program but I have no idea on where to start to make a .dat file.
Quote ...
All I can figure is to make a .txt file and call it Scores.dat
I'm confused. As far as I know, a .dat file is just the same as any other text file. It just a name. Or do you draw a distinction?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 1st, 2005
0

Re: Making a .dat file

I though there was a distinction. I assume I just write the headings with the appropriate information under the headings.

I didn't write the C++ code because I wrote it to read an array. I was confused with the .dat issue.
mb1
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mb1 is offline Offline
7 posts
since Mar 2005
Nov 3rd, 2005
0

Re: Making a .dat file

Yes a .dat is just a different file extention. You can create this in windows with just notepad and when you save it make it filename.dat. Actually, in Linix/Unix it is the same. Just save it with filename.dat.
Reputation Points: 10
Solved Threads: 0
Light Poster
sifuedition is offline Offline
25 posts
since Jul 2005
Nov 3rd, 2005
0

Re: Making a .dat file

Its been my experience that .dat files contain binary data, such as the computer's binary representation of an integer and not the ascii digits that you will find in a text file. .dat files normally can not be easily read by text editors such as Notepad.exe.
Exemple:
C++ Syntax (Toggle Plain Text)
  1. struct mystruct
  2. {
  3. int a;
  4. long b;
  5. float c;
  6. double d;
  7. };
  8.  
  9. int main()
  10. {
  11. myruct s
  12.  
  13. // write the structure to the file
  14. ofstream out("mydata.dat", ios::binary);
  15. out.write((char *)&s,sizeof(s));
  16. out.close();
  17.  
  18. // now read the file
  19. ifstream in("mydata.dat", ios::binary);
  20. in.read((char*)&s,sizeof(s));
  21. in.close();
  22. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: 1 Error Message
Next Thread in C++ Forum Timeline: C books





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC