fstream question

This is a discussion on fstream question within the C++ Programming forums, part of the General Programming Boards category; I have a question about the fstream class constructor: Code: explicit fstream ( const char * filename, ios_base::openmode mode = ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    272

    fstream question

    I have a question about the fstream class constructor:

    Code:
    explicit fstream ( const char * filename, ios_base::openmode mode = ios_base::in | ios_base::out );
    How can the constructor argument be assigned?

    Code:
    = ios_base::in | ios_base::out
    And what is "mode" itself? Is it a class of type openmode?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    The "assignment" is creating a default parameter. If you only send one argument to the fstream constructor, then the second parameter will be defaulted to that value. Default parameters work for all functions, not just constructors.

    mode is a function parameter of type ios_base::openmode. As far as you're concerned as a user of the function, that might be a class or it might be a typedef for a simple type like int, long or unsigned int. It doesn't really matter as long as you pass in the proper types of values.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Usually when using fstream you will only pass in the first parameter. The other params are there for more advanced usages but have been defaulted to default values b/c they are not used that often so it doesn't make sense to require the user to pass in params that 9 times out of 10 no one cares about or needs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie question, C #
    By mate222 in forum C# Programming
    Replies: 4
    Last Post: 12-01-2009, 05:24 AM
  2. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  3. FStream Question
    By CPP-Null in forum C++ Programming
    Replies: 5
    Last Post: 05-25-2003, 01:28 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  5. fstream question!
    By FutureCoder in forum C++ Programming
    Replies: 1
    Last Post: 01-31-2003, 03:06 PM

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