Solved

existing files

Posted on 2000-03-24
2
202 Views
Last Modified: 2010-04-02
how do i use the 2 void function//
for instance for the 1st function i have to read and copy the contents of file01.dat and file02.dat into a 3rd file..
so can someone please help how to do the producers for the file I/O.. and also
i also wanted to know how in them  2nd function to read the merged file from data 3rd file.. so can someone please
show  me an example like this..
0
Comment
Question by:best2380
2 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
What do you mean by "use the 2 void function"?  That doesn't make sense?

>> 1st function i have to read and copy the
>> contents of file01.dat and file02.dat into a
>> 3rd file
Just use 3 fstream objects to open the 3 files.  Read all the information out of the fstream objects for file01 and file02 and write that information to file03.
0
 

Accepted Solution

by:
kishore_joshi earned 20 total points
Comment Utility
// to merg two files into the third file

void merg()
{
      char ch;
      ifstream f1("file01.dat"), f2("file02.dat");// two objects to read

      fstream d1;
                d1.open("file03.dat",ios::app);  // open in append mode
      
               do
      {
            f1.get(ch);
            d1<<ch;

      }while(ch != EOF);
             
               do
      {
            f2.get(ch);
            d1<<ch;

      }while(ch != EOF);

             d1.close(); // close the destination file.
}

/// to read the data that is merged
void merg_read()
{
              char ch;
              ifstream d1("file03.dat");// d1 objects to read data from file03
      
               do
      {
            f1.get(ch);
            cout<<ch;

      }while(ch != EOF);

}
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now