Thread: Can someone please explain this fstream subtlety?

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    88

    Can someone please explain this fstream subtlety?

    Hi all,

    I've written programs before with file i/o in c++. There was one technique I learned for dealing with files and functions, and it seems to be standard (upon googling), but I was hoping someone could explain one of the finer points.

    When dealing with ifstreams, ofstreams, we often pass by reference when a function needs to deal with files. Why do we not need to dereference in the body of the function in order to use it?

    (Yes, I know there is a similar thread right now. But my posting my question in that thread would likely give away the answer to the OP).
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    What exactly do you mean ?
    References are different from pointers in the way that you do not need to dereference them ... or did I misunderstand your question?

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    88
    Quote Originally Posted by manasij7479 View Post
    What exactly do you mean ?
    References are different from pointers in the way that you do not need to dereference them ... or did I misunderstand your question?
    No you understood. I am just tired and have confused passing by reference and passing by pointers. Was able to find some good info on the net, thanks for the reply though. I had actually read about the distinction, but forgotten.

    For the sake of anyone who reads this and has the same question, check out section [8] of this link:

    C++ FAQ <--good stuff here

    EDIT: really need to sleep lol
    Last edited by Ocifer; 02-12-2012 at 01:05 AM.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    88
    It might even be better to change the thread title to "pass by pointer vs. pass by reference" or something, so that others can learn from my confusion. Mods? At heart, this had nothing to do with fstream.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fstream
    By siavoshkc in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:04 PM
  2. About "fstream" in <fstream.h> and <fstream>
    By L.O.K. in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2005, 06:49 PM
  3. MFC and <fstream>
    By simly01 in forum C++ Programming
    Replies: 3
    Last Post: 08-01-2002, 06:24 AM
  4. need help with fstream
    By gull in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 03:05 PM
  5. qs regarding fstream
    By Clane in forum C++ Programming
    Replies: 2
    Last Post: 03-12-2002, 10:37 PM