944,083 Members | Top Members by Rank

Ad:
  • C Code Snippet
  • Views: 2413
  • C RSS
0

Code that stores and retrieves.

by on Apr 12th, 2007
hi every body try out this code it can store your info and then retriaeve it ant any time you wish.
They are two codes each wrote separatly so first write the outputting code and run it.
Then write the inputting code and also run it
have fun:lol:
C Code Snippet (Toggle Plain Text)
  1. //code for out putting on the file private.dat.
  2.  
  3. #include<iostream.h>
  4.  
  5. #include<fstream.h>
  6.  
  7. #include<stdlib.h>
  8.  
  9. void main()
  10.  
  11. {
  12.  
  13. ofstream my_record("private.dat",ios::out);
  14.  
  15. if(!my_record)
  16.  
  17. {
  18.  
  19. cerr<<"the fail can not be created"<<endl;
  20.  
  21. exit(1);
  22.  
  23. }
  24.  
  25. int age;
  26.  
  27. char name[10];
  28.  
  29. int registration;
  30.  
  31. while(cin>>age>>name>>registration)
  32.  
  33. {
  34.  
  35. my_record<<age<<' '<<name<<' '<<registration<<endl;
  36.  
  37. cout<<"---"<<endl;
  38.  
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //code for in putting on the file private.dat.
  48.  
  49. #include<iostream.h>
  50.  
  51. #include<fstream.h>
  52.  
  53. #include<stdlib.h>
  54.  
  55. void display(int,const char*const,int);
  56.  
  57. void main()
  58.  
  59. {
  60.  
  61. ifstream my_record("private.dat",ios::in);
  62.  
  63. if(!my_record)
  64.  
  65. {
  66.  
  67. cerr<<"the fail can not be found"<<endl;
  68.  
  69. exit(1);
  70.  
  71. }
  72.  
  73. int age;
  74.  
  75. char name[10];
  76.  
  77. int registration;
  78.  
  79. cout<<"AGE\t NAME \tREGESTRATION"<<endl;
  80.  
  81. while(my_recod>>age>>name>>registration)
  82.  
  83. diplay(age,name,registration);
  84.  
  85. }
  86.  
  87. void display(int d,const char*const t, int y)
  88.  
  89. {
  90.  
  91. cout<<d<<'\t'<<'\t'<<t<<'\t'<<'t'<<y<<endl;
  92.  
  93. }
Comments on this Code Snippet
Apr 12th, 2007
0

Re: Code that stores and retrieves.

exelent
Newbie Poster
Mpiangu is offline Offline
8 posts
since Apr 2007
Message:
Previous Thread in C Forum Timeline: Server/Client timeout error
Next Thread in C Forum Timeline: atof ??? how can I change from user?





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


Follow us on Twitter


© 2011 DaniWeb® LLC