My problem is how to write a 2-dimensional vector to text file.
I already follow the topic here and here is my code a bit changed to my need :
ofstream output_file("example.txt");
ostream_iterator<int> output_iterator(output_file, "\t");
for ( int i = 0 ; i < temp2d.size() ; i++ )
copy(temp2d.at(i).begin(), temp2d.at(i).end(), output_iterator);
my question is how to write the vector to the file row by row ?
This is what I want:
22 33 44
66 77 88
88 44 22
and so on.
This code writes all the elements of the vector in the same line.
Thanks.
print out a new line character once you’ve copied the row, i.e. at the end of your for loop: