Saving data into txt file but not able to have a new line for a new data [closed]

asked 2015-02-17 02:30:53 -0500

zms gravatar image

Hello there, Please advise me what should I change with the statement to make sure that the new data will be write into the text file on the new line. im trying to put the value from a loop. Here is the code which only save the first data into the text file.

    int whitepix = countNonZero(frame_gray);
    outputfile.open("data.txt");
    outputfile << whitepix << endl;

Appreciate on your response

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2015-02-17 03:04:58.686465

Comments

2

you probably need to show a bit more of the code.

(but i already guess: if outputfile.open("data.txt"); is inside the loop, you overwrite the same file again and again)

berak gravatar imageberak ( 2015-02-17 02:32:40 -0500 )edit
2

Hi Berak, thanks for the response.. yes :) it worked as what u had suggested. Move to the outer loop and the data is saved now!! Appreciate it.

Z

zms gravatar imagezms ( 2015-02-17 02:40:38 -0500 )edit

ah, ok. low hanging fruit ;)

berak gravatar imageberak ( 2015-02-17 02:47:17 -0500 )edit