0

I've been trying all day to write an array into a file but it doesnt work. The code I'm using is:

fstream myfile;
        myfile.open ("array.txt");
	for(int i=0;i<=9;i++)
		{
		 for (j=0; j<9; j++)
		myfile<<array[i][j]<<endl;
		}
	myfile.close();

What am I doing wrong? This works if I knew what I was writing in but since I dont know I'm using this and all I get out are random numbers :(. Any help?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by GhostMonkey
0

You have to tell the fstream object that you want to output with it by typing:

fstream out;
out.open("output.txt", fstream::out);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.