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?

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

fstream out;
out.open("output.txt", fstream::out);

Thanks, worked great :) .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.