0

How can I found out where ofstream is placing a file, or if it is simply failing to do so (and thus, why I cannot find it?)

. . .  long section of legacy code . . .
std::ofstream a_file("debugLog.txt", std::ios_base::app);
a_file << "tgt";
a_file.close();
}
BREAKPOINT

With

#include <fstream>
#include <iostream>
#include <stdio.h>

added to the applications precompiler directives (this is a legacy war-gaming application I'm working on as an apprentice), the application builds and executes without problem. My breakpoints function as they did before I added this code but I cannot find that debuglog.txt file anywhere!?

Is there a way in the Visual Studio Configuration Properties to specify the directory for this sort of thing?

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20
Diche Bach
  • 45
  • 5
  • not an exact duplicate, but this could help: http://stackoverflow.com/q/4807629/3723423 – Christophe Nov 01 '16 at 22:24
  • You should probably figure out what's your process working directory and look there. If you want an external view of your process activity, [process monitor](https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx) will show you exactly where is the file written to, and if the write fail, for what reason. – Eran Nov 01 '16 at 22:26
  • Thanks Christophe. I had seen that thread earlier today and attempted the GetCurrentDirectory(), but the usage was a bit unclear and it looks like Monoceres expanded on his response. I'll have to explore that tomorrow morning when I'm fresh. – Diche Bach Nov 01 '16 at 22:27
  • @DicheBach, Any update? Would you please share the latest information about this issue? – Jack Zhai Nov 06 '16 at 05:51
  • The projects is just getting going so my mentor has been very "Socratic" and let me flop around a bit to get comfortable in the code ;). Combine this with the facts: he is a very busy IT director and this is just one side project that he hasn't worked on for a few years . . . well he doesn't remember every detail. So basically, there already was code in the program to do what I was trying to find a new way to do, and it used fprintf with some very nice relative path algorithms. I did not find process monitor to be very helpful. – Diche Bach Nov 09 '16 at 14:19
  • @DicheBach, does it mean that you have found a better workaround for this issue? If so, would you please post your workaround as the answer? And then mark it, so it would help other community members who get the same issue. For the Process monitor tool or others which just help you find the process file. If it doesn't really help you, just ignore it:). Thanks for you sharing. – Jack Zhai Nov 10 '16 at 12:04

1 Answers1

0

I agree with eran's suggestion, we couldn't get filename or path from ofstream because ostream may be ostringstream that has no file associated with it. So you could use current process' working directory to compose the absolute path or use certain tool to help you find the file like process monitor, windows explorer search or others.

Jack Zhai
  • 6,230
  • 1
  • 12
  • 20