Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Read and Write from a file at once and store the read data into another file.Please anybody help me..
Posted
Comments
OriginalGriff 26-Feb-14 6:05am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
What kind of file(s) are we talking about? What kind of data?
What have you tried? Where are you stuck?
Use the "Improve question" widget to edit your question and provide better information.
debarunb 26-Feb-14 6:44am    
Thanks for ur comment.Actually data is coming from one hardware interface.I want to write that data into a file and read that data from same file and write into another file. But I want read and write operation happens at simultaneously.
debarunb 26-Feb-14 7:04am    
The data is in ASCII format
debarunb 26-Feb-14 8:05am    
Actually data is coming from one hardware interface.I want to write that data into a text file and read that data from that file and write into another text file. But I want read and write operation happens simultaneously i.e. these two process(Read and Write) work at once ..My data is in simple character format.Sir please reply..My English is not good so please co-operate with me :)

1 solution

//Open a file
//you first operation generally performed on an object of one of these classes is to associate it to a real file
//text file streams are those where the ios::binary flag is not included in their opening mode. 
// and then writing on a text file
#include <iostream>
#include <fstream>
using namespace std;


int main () {
  string line;
  ifstream myfile ("read.txt");
  ofstream writefile;
  
  if (myfile.is_open())
  {
    writefile.open ("write.txt");
    while ( getline (myfile,line) )
    {
      cout << line << '\n';
	  writefile << line << '\n';
    }
	writefile.close();
    myfile.close();
  }
  else cout << "Unable to open file"; 
  return 0;
}
 
Share this answer
 
Comments
debarunb 26-Feb-14 22:51pm    
Actually u give me solutions but in this case one file in read mode and another in write mode its true. But I want both the operations happens not one by one it should be happened simultaneously i.e. suppose one file read some data from hardware then another write data that time approx same time.Like one thread read and another thread write that data...
debarunb 27-Feb-14 4:37am    
Please help anyone or give me some good link that I can implement my code..Thanks in Advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900