hey,
we r asked to do a student data base using c++ and I'm having problem in appending in the file without redundancy in my code i'm dealing with strings is it possible to append on the string without creating a new one or i should chose another data type maybe like"array lists or something"

thanks

Post your code down.

cout<<"please enter ur id";
       cin>>idEnroll;
       cout<<"please enter the course u want 2 enroll in";
       cin>>info.courseId;
                   
                       //get the name to search from the user
                       //open the file
                 
                       int counter1;
                       
                       int counter =0;
                       string temp=" ";
                        while (!student2.eof())
                        {
                              student2 >>fWord;
                             //loop till the end of the file
                             int compare=strcmp(fWord,idEnroll);
                             if(compare==0){
                                   getline(student2,temp);
         cout<<temp;
         studen<<temp.append(info.courseId)<<endl;
         studen.clear();
         studen.close();
         counter++;
         break;
               
               }
         }
                 student2.clear();
                 student2.close();                     
                  
                  course.clear();
                   course.close();
         }

ofstream infile; // create a new output stream infile.open ("[I]yourfile[/I]", fstream::app); // open the file for appending

ofstream infile; // create a new output stream infile.open ("[I]yourfile[/I]", fstream::app); // open the file for appending

Output stream named infile... That's cool! ;)

commented: You're absolutely right, logical mistake from me, but the code is still working :P +2

Output stream named infile... That's cool! ;)

That was just a logical mistake from me :P ...

That was just a logical mistake from me :P ...

Remember classics: It's not a mistake: it's a feature...

the problem in appending in the file in a specific string we find a solution by string.find then string.replace but thanks a lot f your great help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.