tiavec88
tiavec88

Reputation: 345

overwriting in a .txt file

I'm writing code with visual c++. My target is writing some double values in a .txt file. The problem is that I'm passing it in a for cicle and everytime there's a file overwrite and so I can see only the last value. (The values of marker1, marker2, marker3 change in every cicle).

ofstream myfile;
myfile.open("C:/Mattia_progetto/LineScannerRealTime/markers.txt");
myfile<<marker1[0]<<"\t"<<marker1[1]<<"\t"<<marker1[2]<<"\t"<<marker2[0]<<"\t"<<marker2[1]<<"\t"<<marker2[3]<<"\t"<<marker3[0]<<"\t"<<marker3[1]<<"\t"<<marker3[2];
myfile.close(); 

How can I solve it?

Upvotes: 0

Views: 172

Answers (1)

fho
fho

Reputation: 500

Pass ios::app as mode flag to myfile.open() to append something to the file instead of overwriting the contents.

See: http://en.cppreference.com/w/cpp/io/basic_ofstream/open

Upvotes: 2

Related Questions