I have a little problem with file I/O.
I want to make a program that can open .cpp file,
modify something and save it in out.cpp .
The problem is that when I save file it
is saved without identation.

I think that problem is in this line :
Code:
ostream_iterator<string> os (file_output, "\n");
When i change "\n" to " ", there are no newlines,
whole code is in one line.
How can I save file without loosing formatting ?

Here is source of function that opens file,
outputs file...
PS: Sorry on mess, i am using tabs, and this board has some problems with tabs...

Code:
/*============================================================
    [function]  :   insertInfoHeader
    
    [arguments] :   1. name of file to open
					2. name of output file
					3. flags class
	
	[Purpose]	:	Inserts header like this 
					above all functions in 
					specified file.
============================================================*/
void insertInfoHeader (char		inputFile[], 
					   char		outputFile[],
					   Flags	&infoHeaderFlags)
{
	ifstream file_input;
	ofstream file_output;

    //  vector for saving contents of file...
	vector <string> file_buffer;
    //  and its iterator
    vector <string>::const_iterator file_bufferBegin;

	//string text;

	try
	{
        cout << "\nOpenning " << inputFile << "...";		
        file_input.open  (inputFile,  ios::in);
        file_output.open (outputFile, ios::trunc);

        if (!(file_input))
            reportError (FileErr ("Input"), OPEN_FAIL);
        if (!(file_output))
            reportError (FileErr ("Output"), OPEN_FAIL);

        const istream_iterator<string> is (file_input);
        const istream_iterator<string> eof;
              ostream_iterator<string> os (file_output, "\n");

        copy (is, eof, back_inserter (file_buffer));

        //  can do stuff to vector now
        //  -
        copy (file_buffer.begin(), file_buffer.end(), os);

        //	iterate through buffer vector
        for (file_bufferBegin = file_buffer.begin();
             file_bufferBegin != file_buffer.end();
             ++file_bufferBegin)
        {
            cout << "\n->\t"
                 << file_buffer.back ();
            file_buffer.pop_back ();
        }

	}
	catch (exception &exc) 
	{
		cout << "\nException catched!\n"
			 << __DATE__ << "\t" << __TIME__ <<" ."
			 << "\nreport : " << exc.what ();
	}		

    //  close opened files
	file_output.close();
    file_input.close ();
}
... and here are the files :

Input :
Code:
Unit::Unit(int Moral, int HP, int Ammo, int ID):_ID(1000)
{
	try
	{
		Unit::_Moral = Moral;
		Unit::_Ammo = Ammo;
		Unit::_HP = HP;
		Unit::_ID = ID;
		incID();
		Unit::_numOf++;

		cout << "\n+\tUnit,\tID| " << Unit::_ID;
		cout << " |.\t total | " << Unit::_numOf << " | units.\t+"
			 << "\n______________________________________________________________";
	}
	catch(exception &exc)
	{
		cerr << exc.what();
	}
}
... and output:
Code:
Unit::Unit(int
Moral,
int
HP,
int
Ammo,
int
ID):_ID(1000)
{
try
{
Unit::_Moral
=
Moral;
Unit::_Ammo
=
Ammo;
Unit::_HP
=
HP;
Unit::_ID
=
ID;
incID();
Unit::_numOf++;
cout
<<
"\n+\tUnit,\tID|
"
<<
Unit::_ID;
cout
<<
"
|.\t
total
|
"
<<
Unit::_numOf
<<
"
|
units.\t+"
<<
"\n______________________________________________________________";
}
catch(exception
&exc)
{
cerr
<<
exc.what();
}
}
*Sorry on lengthy post....