I'm trying to write to a file but I am getting an error that I believe is because I need to overload my insertion operator. This is what I have so far
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct color
{
unsigned char r;
unsigned char g;
unsigned char b;
};
void initialize(color arr[][600], int nrows, int ncols);
void writeAll(color arr[][600], int nrows, int ncols);
const int NROWS = 400;
const int NCOLS = 600;
int main()
{
color arr[400][600];
initialize(arr, 400, 600);
writeAll(arr, 400, 600);
return 0;
}
// Background
void initialize(color arr[][NCOLS], int nrows, int ncols)
{
for (int row = 0; row < NROWS / 2; row++)
{
for (int col = 0; col < NCOLS / 2; col++)
{
arr[row][col].r = 255;
arr[row][col].g = 255;
arr[row][col].b = 255;
}
}
}
void writeAll(color arr[][600], int nrows, int ncols)
{
ofstream fout("out.ppm", ios::out | ios::binary);
fout << "P6" << endl;
fout << ncols << " " << nrows << endl;
fout << 255 << endl;
for (int row = 0; row < nrows; row++)
{
for (int col = 0; col < ncols; col++)
{
fout << arr[row][col];
}
}
fout.close();
}
The line
fout << arr[row][col];
is giving me an error "no operator "<<" matches these operands
From the research I've done it seems like I have to overload that operand, but I cannot find anything about overloading something that's not a class.