output data to a file (.csv or .txt)

I currently am trying to output the centroid values of a single blob to a text file.

I am able to identify the centroids x and y of the blobs through this line in the void TestApp::Draw

    for (int i = 0; i < contourFinder.nBlobs; i++){  
        getX = contourFinder.blobs.at(i).centroid.x;  
        getY = contourFinder.blobs.at(i).centroid.y;  

and when i attempt to print them to the terminal i use this line in the void TestApp::update

cout << getX << " " << getY << endl;  

and it outputs lines and lines of coordinates for the centroids.

But when i attempt to insert this in the same place…

ofstream myfile ("data.csv");  
        if (myfile.is_open())  
            myfile << getX << ',' << getY << "\t";  

All i get are 2 values, one in the A1 and the other in the B1 cells.
These two values are the last values that appear just before I close the application.

I wonder what happens to all the other values?

oh, and i forgot, i am using code::blocks 10.05 with the v0062 pre release on windows xp.

what’s happening is that you’re rewriting the same piece of file; look for ios::app