944,030 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1620
  • C++ RSS
May 20th, 2006
0

Re: assignment help [fstream, on modifying a record in a file]

Expand Post »
<<split from: http://www.daniweb.com/forums/showthread.php?t=42172>>
Quote originally posted by weehoong ...
Hi there guys!

Just want to say these communities are great! i've really benefited alot from the forum and its tutorials. Special thanks to FireNet and his file handling tutorials. It really helped me alot! Not forgetting, thanks alot to all of the members here too. :cheesy:

anyway, ive got this assignent to finish off and are having problems with a small block of codes here.

C++ Syntax (Toggle Plain Text)
  1.  
  2. class video
  3. {
  4.  
  5. protected:
  6.  
  7. struct videoData
  8. {
  9. char title[30];
  10. char star1[30];
  11. char star2[30];
  12. char producer[30];
  13. char director[30];
  14. char productionCo[30];
  15. int copiesInStock;
  16. int totalCopiesInStock;
  17. };
  18.  
  19. public:
  20.  
  21.  
  22. //////[Modify Record]/////////////////////////////////////////////////////
  23.  
  24. void modifyVideoList()
  25. {
  26.  
  27. fstream file4;
  28. videoData fields;
  29. char titleTemp [30];
  30.  
  31. int flag=0;
  32.  
  33. cout<<"\t\n\nEnter title of video to search: \n";
  34. cin.getline(titleTemp,30);
  35.  
  36. file4.open("videolist.dat", ios::app | ios::out | ios::in | ios::binary);
  37. file4.seekg(0, ios::beg);
  38. file4.read( reinterpret_cast<char*>(&fields), sizeof(fields) );
  39.  
  40. while ( !file4.eof())
  41. {
  42.  
  43.  
  44. if(strcmp(fields.title,titleTemp)==0)
  45. {
  46.  
  47. //Display old record information
  48. cout<< "\n\t::Displaying '" << fields.title << "' information::\n";
  49. cout<< "Movie Title: " << fields.title <<endl;
  50. cout<< "Movie Star 1: " << fields.star1 <<endl;
  51. cout<< "Movie Star 2: " << fields.star2 <<endl;
  52. cout<< "Movie Producer: " << fields.producer <<endl;
  53. cout<< "Movie Director: " << fields.director <<endl;
  54. cout<< "Production Company: " << fields.productionCo <<endl;
  55. cout<< "Number of Copies In Stock: " << fields.copiesInStock <<endl;
  56. cout<< "Total Copies in Store: " << fields.totalCopiesInStock <<endl;
  57.  
  58. cout<< "\n\n";
  59.  
  60. //Enter new record information
  61. cout<< "\n\n"<<endl;
  62. cout<< "\t::Enter new information::\n"<<endl;
  63.  
  64. cout<<"Video Title: ";
  65. cin.getline(fields.title, 30);
  66.  
  67. cout<<"Movie Star 1: ";
  68. cin.getline(fields.star1, 30);
  69.  
  70. cout<<"Movie Star 2: ";
  71. cin.getline(fields.star2, 30);
  72.  
  73. cout<<"Movie Producer: ";
  74. cin.getline(fields.producer, 30);
  75.  
  76. cout<<"Movie Director: ";
  77. cin.getline(fields.director, 30);
  78.  
  79. cout<<"Production Company: ";
  80. cin.getline(fields.productionCo, 30);
  81.  
  82. cout<<"Number of Copies in Stock: : ";
  83. cin>> fields.copiesInStock;
  84.  
  85. cout<<"Total Copies in Store: ";
  86. cin>> fields.totalCopiesInStock;
  87.  
  88. file4.seekp(0, ios::beg);
  89. file4.write( reinterpret_cast<char*>(&fields), sizeof(fields) );
  90.  
  91.  
  92. }
  93. file4.read( reinterpret_cast<char*>(&fields), sizeof(fields) );
  94.  
  95. }
  96.  
  97. if(flag==1)
  98. {
  99. cout<<"Video title not found!"<<endl;
  100. fflush(stdin);
  101. }
  102.  
  103. cout<< "\nRecord has been updated!\n" <<endl;
  104.  
  105. file4.close();
  106. system("Pause");
  107. system("Cls");
  108.  
  109.  
  110. }

what im trying to do here is to create a file handling database with add, display records and modify records for a video rental store. the problem here is the modify record section where i cant get any datas into my file.

can anyone help me with this? this block of codes are copied from my header file so if anyone needs the whole thing please tell me so. thanks alot!
hi, well i m too in creation of something similar to your code. But i need help in generating a file whatever the user does while interacting with executed code...i mean saving the output of executed code in a file....
can anyone help me
Last edited by Dave Sinkula; May 20th, 2006 at 9:06 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sufi is offline Offline
1 posts
since May 2006
May 20th, 2006
0

Re: assignment help [fstream, on modifying a record in a file]

just open the file for writing, then output all user input to that file. Yes, you have to add additional code to do that. No, you can't have cout and cin do two things at the same time (write/read to/from the screen and write to a file too).
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: Memory game with c++ console applicaton
Next Thread in C++ Forum Timeline: Problem with user input





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


Follow us on Twitter


© 2011 DaniWeb® LLC