Mar 28, 2010 at 2:28am UTC
How do I print the result of this code to a Text file?
#include <iostream>
#include <fstream>
using namespace std;
for(int level=0; level<LEVELS; level++) {
for(int row=0; row<ROWS; row++) {
for(int col=0; col<COLS; col++) {
if (col==0||col==3) {
cabins[level][row][col] = (row<5) ? 'B' : 'W';
} else {
cabins[level][row][col] = 'I';
}
}
}
}
for(int level=0; level<LEVELS; level++) {
cout << "--------------- LEVEL " << (level + 1) << " --------------------------" << endl;
cout << '+';
for(int col=0; col<COLS; col++) { cout << '\t' << (col+1); }
cout << endl;
for(int row=0; row<ROWS; row++) {
cout << (row + 1);
for(int col=0; col<COLS; col++) {
cout << '\t' << cabins[level][row][col];
}
cout << endl;
}
cout << endl;
}
system ("pause");
return 0;
}
Mar 28, 2010 at 3:59am UTC
Is doing it with C++ a requirement? If it isn't you can just redirect the shell output.
Let's say your executable is named a.exe
at the command prompt:
a.exe > somefile.txt
will take any output from a.exe and put it in a file name somefile.txt.