Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Standard way to implement plain text and binary input/output methods

Standard way to implement plain text and binary input/output methods

Scheduled Pinned Locked Moved C / C++ / MFC
helpdiscussion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skippums
    wrote on last edited by
    #1

    I need to implement a class that offers a client two ways to output data, depending on if they want to display it in ASCII or store it in binary. I figured the best way to implement the ASCII output would be to use a friend function as follows:

    friend ostream& operator <<(ostream&, myClass const&);

    However, to offer a binary output option, I don't know whether I should create a friend function or a class method, and was wondering if there is an accepted best practice in such a scenario. The two options I am considering are:

    friend ostream& write(myClass const&); // Option 1
    void write(ostream&) const; // Option 2

    If either of these methods (or some other method) is the preferred way of offering such functionality, I would be interested to hear about it. Similarly, I need to implement the binary input method, for which I have the following three conceivable options:

    friend istream& read(myClass&); // Option 1
    void read(ostream&); // Option 2
    static void read(myClass *&, ostream&); // Option 3

    Thanks for the help,

    Sounds like somebody's got a case of the Mondays -Jeff

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups