Start New Discussion within our Software Development Community

Hi,

i have five{number is unimportant} independent objects{the purpose is to model sensors} and i want them to write sequentially{not in the same time}, some info to a file{all to the same file} and at screen...

i was thinking to implement a fileWriter class, that will create the file...and then pass a reference {of an object of fileWriter class} to each of the five objects-sensors, so they can write to the same file.

The problem is that i dont know if this is the best way to do this{object oriented speaking} and if this is the way how can i implement this system similar to cout?
In particular someone can use cout anywhere in his program{if he includes iostream} and always the output is the same{stdout}....

Last question::does anyone have a good link for input-output in c++?

thanks for your time,
N.A

Hmm... perhaps you want to overload the behaviour of << ? I'd say create a base class [B]CFileWrite[/B] which implements member functions which print to a file and to the screen.

Then perhaps for each sensor object you overload the << operator to your needs.

class CFileWrite {
    protected:
    void printToFileAndScreen(string data);
};

class CSensor : public CFileWrite {
   friend ostream& operator<<(ostream &s, CSensor &obj);

};

Your overloaded << can print out any necessary information from the class. Additionally, you could apply this to CFileWrite so that each individual sensor class doesn't have to overload the << if they don't want to.

This article has been dead for over six months. Start a new discussion instead.