copy txt line2line

hi i have a little problem...i have to copy a txt to another txt but i nedd to modify the 3 line and add a new line at the fine of the file...how can i do this??
i want do the copy in line to line so i can do the right change at the line choose....
i use this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
std::ifstream infile ("infile.txt");
            std::ofstream outfile ("outfile.txt");
            std::string line;
            int num;
            outfile<<"ciao"<<std::endl;
            while(!infile.eof())
            {
                    //bool loop=true;
                    getline(infile,line);
                    if (line.at(0)!='#')
                    {
                        num=atoi(line.c_str())+1;
                        outfile<<num<<std::endl;
                        //loop=false;
                    }
                    outfile<<line<<std::endl;

            }


this code didn't finish..so if anyone can help me please write...byebye
NB sorry for my english...i'm a young italian boy!!!byebye
Topic archived. No new replies allowed.