Hi,

I am trying to write strings to a file line by line and trying to format the output so that the alignment is proper.
output should be
it should appear in the output file as

david      10   15   16 
sam        11   15   16   

but appears as david 10 15 16 sam 11 15 16 there is no new line all output is on the same line despite using endl.
my code is attached below..pls tell me thats wrong, or if some other method exists to implement the above as i want the numbers to be aligned column wise.
Note: all parameters are strings like david ,10,15,16 will all be seperate strings

bool WriteOutputFile(string line)
{
string Outline;
int linelength;

    Outline=line;
    Outline.resize(Outline.length()+20);

    ofstream Outfile ("result.txt", ios::out | ios::app );
    if(Outfile.is_open())
    {
        Outline.insert(20,"10");
        Outline.insert(25,"15");
        Outline.insert(30,"16");

        Outfile<<Outline<<endl;
    }
    Outfile.close();
}

hi,
Did u try writing the '\n' char instead of 'endl'?

thanks jonsca

it worked like a charm using setw is so much easier...and i got the solution of the new line issue seems cygwin recognises /r as new line command!

thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.