Click here to Skip to main content
11,437,397 members (33,932 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
How to Read and Write from a file at once and store the read data into another file.Please anybody help me..
Posted 26-Feb-14 0:42am
debarunb1.1K
Comments
OriginalGriff at 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 at 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 at 26-Feb-14 7:04am
   
The data is in ASCII format
debarunb at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

//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;
}
  Permalink  
Comments
debarunb at 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 at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.150428.2 | Last Updated 26 Feb 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100