I am creating a class for writing file in c++, and i have this code so far,
#include "stdafx.h" #include <iostream> #include <string> #include <stdlib.h> #include <fstream> using namespace std; class FileWriter { private: bool isLittleEndian; ofstream file; public: FileWriter(string fileName) : file("data.bin", ios::out | ios::binary) { int i = 1; char *p = (char *)&i; if(p[0] == 1) isLittleEndian = true; } void writeByte() { } void writeShort() { } void writeInt() { } void writeLong() { } void writeUnsignedByte() { } void writeUnsignedShort() { } void writeUnsignedInt() { } void writeUnsignedLong() { } void writeFloat() { } void writeDouble() { } void writeString() { } void closeFile() { file.close(); } }; int main() { FileWriter writer = FileWriter("C:\\Users\\Owner\\Desktop\\Test.bin"); writer.closeFile(); return 0; } but for some reason, it wont let me have an ofstream field, and when i try it says, Error 1 error C2248: 'std::basic_ofstream<_Elem,_Traits>::operator =' : cannot access private member declared in class 'std::basic_ofstream<_Elem,_Traits>' c:\users\owner\documents\visual studio 2012\projects\bytetests\bytetests\bytetests.cpp 25 1 I need this because functions in my class need to manipulate this stream. I don't see why this so hard to do.