I’m trying to output every element of my array into a .txt file but for some reason it doesn’t even create the file. I have both a cmd output and file output in my display method which is called from the main. The cmd output works perfectly but when i use ofstream to try and create a file and output the array’s element to it, i don’t see any text file created.
ofstream ofs("TEST.txt");
if(!ofs)
cout << "cannot use" << endl;
else
{
for(int a=0; a < 12; a++)
{
for(int b=0; b < 12; b++)
{
cout << RandomArray[a][b] << "\t";
ofs << RandomArray[a][b];
}
cout << "\n";
}
}
ofs.close();
try this
The win32 GetLastError() #define isn’t tested, as I don’t have a windows box handy. The errno bit works. this will at least tell you what the error is if the file open fails