Redifinition of fstream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kiarash
    New Member
    • Sep 2006
    • 3

    Redifinition of fstream

    Hi,

    I want to open & close multiple files in a for loop.I have two problems :

    1.How can I define an array of file names to be entered to "fstream" function?

    2.How can I avoid redefiniton error for redefining an fstream variable?

    I would be thankful if any one can help me.
  • kky2k
    New Member
    • May 2007
    • 34

    #2
    Originally posted by kiarash
    Hi,

    I want to open & close multiple files in a for loop.I have two problems :

    1.How can I define an array of file names to be entered to "fstream" function?

    2.How can I avoid redefiniton error for redefining an fstream variable?

    I would be thankful if any one can help me.
    Read the guidelines before posting...

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Have you considered creating a vector<fstream> files???

      You could create an fstream variable and open it as File 1 then do a push_back() in to the vector.

      Use the same variable to open File 2 and push_back() again to the vector.

      Then just use files[i] to reference a particular fstream.

      Comment

      Working...