edit txt file help

This is a discussion on edit txt file help within the C++ Programming forums, part of the General Programming Boards category; hi eveyone i need to edit person name or Appointmendescription but not date or time in my program. i can ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    24

    Exclamation edit txt file help

    hi eveyone
    i need to edit person name or Appointmendescription but not date or time in my program. i can write all the records to the file and can read from the file.
    and need to edit the file now. can anyone help????
    thanks..
    Code:
    void writeAppointmenRecords( )
    {
    	int index;
    		//create and open an output text file
    
           ofstream outfile("C:\\AppointmenRecords.txt",ios::out | ios::app);
    	   // Check if file is opened
                if(!outfile)          //return true if file is not opened
    	  {  cout<<"\nFailed to open file!!!!\n";
             cout<<"\nPress any key to proceed ";
    		 cin.get();        //read a character         
    	  }
    		
    	for (index=0; index<currentSize; index++)
    	{
            outfile<<AppointmenList[index].name<<endl;
    		outfile<<AppointmenList[index].description<<endl;
    		outfile<<AppointmenList[index].time<<endl;
    		outfile<<AppointmenList[index].appdate.day<<" ";
    		outfile<<AppointmenList[index].appdate.mounth<<" ";
    		outfile<<AppointmenList[index].appdate.year<<endl;
    	}  
         //write records to the file.
    		outfile.close( );    // close file
    		cout<<"\n\nRecord(s) has been written to the file successfully!!!"<<endl;
    		cin.get();
    }
    
    void readAppointmenRecords( )
    {  
    	//create a stream and open the file 'AppointmenRecords.txt' for input
    
    	 ifstream infile("C:\\AppointmenRecords.txt", ios::in);
    		// check if file is opened
    		  if(!infile)          //return true if file is not opened
    	  {  cout<<"\nFailed to open file!!!!\n";
    	                            //indicate program failed
    	  cin.get();
    	  }
    		  while (!infile.eof())    //eof( ) End Of File function. Returns false if end file reached
           {
    		infile>>AppointmenList[currentSize].name;
    		infile>>AppointmenList[currentSize].description;
    		infile>>AppointmenList[currentSize].time;
    		infile>>AppointmenList[currentSize].appdate.day;
    		infile>>AppointmenList[currentSize].appdate.mounth;
    		infile>>AppointmenList[currentSize].appdate.year;
    		currentSize+=1;
            }
        infile.close( ); // close file
    	currentSize = currentSize -1;
    	cout<<"\n\nRecords has been read from the file successfully!!!"<<endl;
    	cin.get();
        
    }
    void editAppointmenRecords( )
    {
    	int editname;
    	system("cls");  //clear screen
    	cout<<"\nEnter person Name you want to Edit: ";
    	cin>>editname;
    	ifstream edfile("C:\\AppointmenRecords.txt");
    	if(!edfile)          //return true if file is not opened
    	  {  cout<<"\nFailed to open file!!!!\n";       //indicate program failed
    		 cin.get();                       
    	  }
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what else do you think you need to do to edit a field?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    24
    i just need edit name or description nothing else.
    but i dont know how to do.
    can you give me any exaples
    my write and read options working fine.
    thanks

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, what EXACTLY is it you want an example of?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    24
    like finding and editing something from file.
    Code:
    void editAppointmenRecords( )
    {
    	int editname;
    	system("cls");  //clear screen
    	cout<<"\nEnter person Name you want to Edit: ";
    	cin>>editname;
    	ifstream edfile("C:\\AppointmenRecords.txt");
    	if(!edfile)          //return true if file is not opened
    	  {  cout<<"\nFailed to open file!!!!\n";       //indicate program failed
    		 cin.get();                       
    	  }
    }
    i started like that but get confused.
    im a beginer so i dont know too much still studying.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Retrieve string(s) from (txt) file
    By Gordon in forum Windows Programming
    Replies: 12
    Last Post: 08-10-2007, 04:34 PM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 11:51 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21