I'm having an issue with my app at midnight when it's meant to start writing to a new log file. I've created this demo app (spooling a new file every min) to highlight / work the issue. If anyone has any ideas, any help is greatly appreciated.
It looks as if once reopened, the fileOResults is only accessible from within the IF block.
Line 22 above creates a new ofstream variable with the same name as fileOResults but that is scoped to the enclosing if statement. Just open the new file without creating a new ofstream variable.
Thanks you dutch, that works a treat. Makes perfect sense once you said it.
I didn't think the compiler would allow two variables of the name name to be defined, that that's a lesson learned.
I also didn't know that variables could be confined to within an IF statement. I was on the false impression when starting out the smallest scope would be to within a procedure (i.e. Main) or function. I later realised it must be constrained smaller, but had the syntax issue to overcome as well.
Everyday's a school day. Thank you - Very much appreciated :-)
the compiler would allow two variables of the same name to be defined
It will if there are at different scope levels. The one defined at an 'inner' scope is used. At the end of a scope, variables defined in that scope are no longer available.