Making a .dat file

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2005
Posts: 7
Reputation: mb1 is an unknown quantity at this point 
Solved Threads: 0
mb1 mb1 is offline Offline
Newbie Poster

Making a .dat file

 
0
  #1
Nov 1st, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 255
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Making a .dat file

 
0
  #2
Nov 1st, 2005
Show us your basic attempt start to the code with [code][/code] tags.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 7
Reputation: mb1 is an unknown quantity at this point 
Solved Threads: 0
mb1 mb1 is offline Offline
Newbie Poster

Re: Making a .dat file

 
0
  #3
Nov 1st, 2005
All I can figure is to make a .txt file and call it Scores.dat

In the file:

  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 255
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Making a .dat file

 
0
  #4
Nov 1st, 2005
I've got the program
You've got a program that reads from the .dat file, so why not post that?
program but I have no idea on where to start to make a .dat file.
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?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 7
Reputation: mb1 is an unknown quantity at this point 
Solved Threads: 0
mb1 mb1 is offline Offline
Newbie Poster

Re: Making a .dat file

 
0
  #5
Nov 1st, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 25
Reputation: sifuedition is an unknown quantity at this point 
Solved Threads: 0
sifuedition's Avatar
sifuedition sifuedition is offline Offline
Light Poster

Re: Making a .dat file

 
0
  #6
Nov 3rd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Making a .dat file

 
0
  #7
Nov 3rd, 2005
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:
  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. }
Reply With Quote Quick reply to this message  
Reply

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




Views: 18240 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC