Thread: Revisited an old problem

  1. #16
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    I recommend you look here (ofstream::ofstream - C++ Reference) and also at the open method, to figure out how to open ofstreams.

    I also recommend you get your files more organized. When you start getting errors like what you describe here:
    If I change from *b_file* to *e_file* in the second part, I get an *e_file is undefined* error. Is it the *ifstream* statement that DEFINES the file & opens it for reading?
    You're only starting to lose track of what you're doing. You didn't really explain why you keep changing the name of your file objects. I'm compelled to tell you that you can name them anything descriptive. Don't get caught up in minutiae before the program even works. I typically give my file objects plain names like "report".

    If you have to process even a lot of files, you should tackle them one at a time. Keep one ifstream object alive to read from, and ofstream object alive to write or append to, and iterate over an array of file paths, with the body of the loop doing IO operations.
    Last edited by whiteflags; 04-21-2012 at 06:07 PM. Reason: kill the smilies

  2. #17
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Therry View Post
    What am I doing wrong?
    Two things come to mind:
    1. How can I further clarify what I wrote in post #11? You haven't yet understood what we're trying to tell you about how you are using two totally unrelated variables. You're opening a file with the variable out1, then you're writing to a file through a variable d_file.
    I never said you should comment out a check for the file not being opened successfully. On the contrary it should be left in, but you need to give the correct error message and use the correct variable.

    2. Will you please preview your posts, or at least re-edit them after saving. You're not getting half of your code blocks correct.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iteration revisited
    By robwhit in forum C Programming
    Replies: 3
    Last Post: 09-05-2007, 09:38 AM
  2. C language revisited
    By oloc in forum C Programming
    Replies: 2
    Last Post: 05-12-2005, 04:34 PM
  3. nop - revisited
    By oioi in forum Tech Board
    Replies: 4
    Last Post: 12-28-2004, 10:18 AM
  4. VSD revisited
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 05-01-2004, 04:27 PM