outputing a 2d array to file

hi,
i am new to c++ and not sure how to output an array to file in a particular structure. the file needs to have elements of each row seperated by spaces or commas and each row needs to start on a different line.

ie if i had a 3x3 array int A[3][3]={{11,12,13},{14,15,16},{17,18,19}}
how would i get it to save to file (.dat or .txt) in the format:

11 12 13
14 15 16
17 18 19

i can output the array to file in form: 11 12 13 14 15 16 17 18 19 but don't know how to make it start a new line after every nth element.

please help :)
You should be using 2 for loops for reading the data, from that you can add an end line at each pass on the first loop
Topic archived. No new replies allowed.