:cheesy:
class video { protected: struct videoData { char title[30]; char star1[30]; char star2[30]; char producer[30]; char director[30]; char productionCo[30]; int copiesInStock; int totalCopiesInStock; }; public: //////[Modify Record]///////////////////////////////////////////////////// void modifyVideoList() { fstream file4; videoData fields; char titleTemp [30]; int flag=0; cout<<"\t\n\nEnter title of video to search: \n"; cin.getline(titleTemp,30); file4.open("videolist.dat", ios::app | ios::out | ios::in | ios::binary); file4.seekg(0, ios::beg); file4.read( reinterpret_cast<char*>(&fields), sizeof(fields) ); while ( !file4.eof()) { if(strcmp(fields.title,titleTemp)==0) { //Display old record information cout<< "\n\t::Displaying '" << fields.title << "' information::\n"; cout<< "Movie Title: " << fields.title <<endl; cout<< "Movie Star 1: " << fields.star1 <<endl; cout<< "Movie Star 2: " << fields.star2 <<endl; cout<< "Movie Producer: " << fields.producer <<endl; cout<< "Movie Director: " << fields.director <<endl; cout<< "Production Company: " << fields.productionCo <<endl; cout<< "Number of Copies In Stock: " << fields.copiesInStock <<endl; cout<< "Total Copies in Store: " << fields.totalCopiesInStock <<endl; cout<< "\n\n"; //Enter new record information cout<< "\n\n"<<endl; cout<< "\t::Enter new information::\n"<<endl; cout<<"Video Title: "; cin.getline(fields.title, 30); cout<<"Movie Star 1: "; cin.getline(fields.star1, 30); cout<<"Movie Star 2: "; cin.getline(fields.star2, 30); cout<<"Movie Producer: "; cin.getline(fields.producer, 30); cout<<"Movie Director: "; cin.getline(fields.director, 30); cout<<"Production Company: "; cin.getline(fields.productionCo, 30); cout<<"Number of Copies in Stock: : "; cin>> fields.copiesInStock; cout<<"Total Copies in Store: "; cin>> fields.totalCopiesInStock; file4.seekp(0, ios::beg); file4.write( reinterpret_cast<char*>(&fields), sizeof(fields) ); } file4.read( reinterpret_cast<char*>(&fields), sizeof(fields) ); } if(flag==1) { cout<<"Video title not found!"<<endl; fflush(stdin); } cout<< "\nRecord has been updated!\n" <<endl; file4.close(); system("Pause"); system("Cls"); }
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)
class video { protected: struct videoData { char title[30]; char star1[30]; char star2[30]; char producer[30]; char director[30]; char productionCo[30]; int copiesInStock; int totalCopiesInStock; }; public: //////[Modify Record]///////////////////////////////////////////////////// void modifyVideoList() { fstream file4; videoData fields; char titleTemp [30]; int flag=0; cout<<"\t\n\nEnter title of video to search: \n"; cin.getline(titleTemp,30); file4.open("videolist.dat", ios::app | ios::out | ios::in | ios::binary); file4.seekg(0, ios::beg); file4.read( reinterpret_cast<char*>(&fields), sizeof(fields) ); while ( !file4.eof()) { if(strcmp(fields.title,titleTemp)==0) { //Display old record information cout<< "\n\t::Displaying '" << fields.title << "' information::\n"; cout<< "Movie Title: " << fields.title <<endl; cout<< "Movie Star 1: " << fields.star1 <<endl; cout<< "Movie Star 2: " << fields.star2 <<endl; cout<< "Movie Producer: " << fields.producer <<endl; cout<< "Movie Director: " << fields.director <<endl; cout<< "Production Company: " << fields.productionCo <<endl; cout<< "Number of Copies In Stock: " << fields.copiesInStock <<endl; cout<< "Total Copies in Store: " << fields.totalCopiesInStock <<endl; cout<< "\n\n"; //Enter new record information cout<< "\n\n"<<endl; cout<< "\t::Enter new information::\n"<<endl; cout<<"Video Title: "; cin.getline(fields.title, 30); cout<<"Movie Star 1: "; cin.getline(fields.star1, 30); cout<<"Movie Star 2: "; cin.getline(fields.star2, 30); cout<<"Movie Producer: "; cin.getline(fields.producer, 30); cout<<"Movie Director: "; cin.getline(fields.director, 30); cout<<"Production Company: "; cin.getline(fields.productionCo, 30); cout<<"Number of Copies in Stock: : "; cin>> fields.copiesInStock; cout<<"Total Copies in Store: "; cin>> fields.totalCopiesInStock; file4.seekp(0, ios::beg); file4.write( reinterpret_cast<char*>(&fields), sizeof(fields) ); } file4.read( reinterpret_cast<char*>(&fields), sizeof(fields) ); } if(flag==1) { cout<<"Video title not found!"<<endl; fflush(stdin); } cout<< "\nRecord has been updated!\n" <<endl; file4.close(); system("Pause"); system("Cls"); }
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!![]()
if i assign lets say
char video[40];
and for example a word "hello world" is in that video[40]. if i want to updat it to "hello big world"
is that suppose to mean i already have a fix memory space?
If its ok can someone please provide me a little bit of sample code on how this update thing suppose to be done. thanks alot!
#include <iostream> #include <string> int main() { std::string crap="hello"; crap=crap+" big world"; //ammend the string std::cout<<crap; //new string; std::cout<<"\nHey that was easy!"; std::cin.get(); return 0; }
What im stucked here is to modify a record. I really need some answers on how i can do this. Ive done tons of research about how to do it and really have the concepts on how to do it but i dont konw how to implement it!| DaniWeb Message | |
| Cancel Changes | |