Like Tree1Likes
  • 1 Post By manasij7479

Can someone please explain this fstream subtlety?

This is a discussion on Can someone please explain this fstream subtlety? within the C++ Programming forums, part of the General Programming Boards category; Hi all, I've written programs before with file i/o in c++. There was one technique I learned for dealing with ...

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

    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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    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?
    Ocifer likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    82
    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 12:05 AM.
    W7, Ubuntu -- mingw, gcc, g++, code::blocks, emacs, notepad++

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    82
    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, 09: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, 05: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, 02:05 PM
  5. qs regarding fstream
    By Clane in forum C++ Programming
    Replies: 2
    Last Post: 03-12-2002, 09:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21