write array to file in a nice order

Hello everyone

I want to write an array to file like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 6 6 6 6 6 6 6 4 4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 6 6 6 6 6 6 6 4 4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 6 6 6 6 6 6 6 4 4
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 6 6 6 6 6 6 6 4 4
1 1 1 1 4 4 1 1 1 1 1 1 1 1 1 5 6 6 6 6 6 6 6 4 4
1 1 1 4 4 4 4 1 1 1 1 1 1 1 1 5 6 6 6 6 6 6 6 4 4
1 1 1 4 4 4 1 1 1 1 1 1 1 1 1 5 5 5 5 5 5 5 5 5 1
1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 1
1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 6 6 6 1 1 1 1 1 1 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 6 6 6 6 6 6 6 6 6 3 3 3 3 3 3 3 1
1 1 1 1 1 1 1 1 6 6 6 6 6 6 6 6 6 3 3 3 3 3 3 3 1
2 2 2 2 1 2 1 2 2 2 2 1 1 1 2 2 2 2 2 2 2 2 2 2 2


but the problem when i write the array to file it show all in one line. i want the array to be written in multiple lines like above not in one big line. can you guys tell me how can i do that?

I spend the last 30min trying but nothing is working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <fstream>
#include <string>

int main()
{
int map[19][25]={	
 {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
						{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,6,6,6,6,6,6,6,4,4},
						{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,6,6,6,6,6,6,6,4,4},
						{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,6,6,6,6,6,6,6,4,4},
						{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,6,6,6,6,6,6,6,4,4},
						{1,1,1,1,4,4,1,1,1,1,1,1,1,1,1,5,6,6,6,6,6,6,6,4,4},
						{1,1,1,4,4,4,4,1,1,1,1,1,1,1,1,5,6,6,6,6,6,6,6,4,4},
						{1,1,1,4,4,4,1,1,1,1,1,1,1,1,1,5,5,5,5,5,5,5,5,5,1},
						{1,1,1,1,4,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,1},
						{1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,6,6,6,3,3,3,3,3,3,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,6,6,6,3,3,3,3,3,3,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,6,6,6,3,3,3,3,3,3,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,6,6,6,3,3,3,3,3,3,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,6,6,6,1,1,1,1,1,1,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,6,6,6,6,6,6,6,6,6,3,3,3,3,3,3,3,1},
						{1,1,1,1,1,1,1,1,6,6,6,6,6,6,6,6,6,3,3,3,3,3,3,3,1},
						{2,2,2,2,1,2,1,2,2,2,2,1,1,1,2,2,2,2,2,2,2,2,2,2,2}
};

	//Write File ////////////////////////////////////////////////////////////////
	std::ofstream WriteFile("Map.Data");
	if(WriteFile.is_open())
	{
		for(int x = 0; x < 19; x++)
		{
			for(int y = 0; y < 25; y++)
			{
				WriteFile << map[x][y] << " " << "\n";
			}
		}
		WriteFile.close();
	}
	else
		std::cout<<"Unable to open file";
	//Write File ////////////////////////////////////////////////////////////////
	system("Pause");
	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
for(int y = 0; y < 25; y++)
{
	for(int x = 0; x < 19; x++)
	{
		WriteFile << map[x][y] << " ";
	}
	WriteFile << "\n";
}
thank you so very much :D
Topic archived. No new replies allowed.