icyfire
icyfire

Reputation: 1270

Datafile Handling

While copying the content of one file to another using the function, I just want to ignore the first line of the source file and copy the rest to destination. How to do it?

I copy files like this

I will open ifstream named f1 and ofstream named f2 . Then I will read a line from f1 using f1.getline() and output it to f2.

Upvotes: 0

Views: 105

Answers (2)

selalerer
selalerer

Reputation: 3924

Just read the first line and don't do anything with it and write the rest to the output file:

std::ifstream f1("intput.txt");
std::ofstream f2("output.txt");

f1.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
f2 << f1;

Upvotes: 1

Diego R. Alcantara
Diego R. Alcantara

Reputation: 114

You can use a variable.

In your while or for loop, put an instruction that tell you if you passed the first line

     int flag = 0;
     while(condition){
           if(flag == 0){
           flag = 1;
           continue;
           }
     /*the rest of the code*/
     }

So, the first line will be skipped.

Upvotes: 0

Related Questions