I have function whose signature is something like so:
void someFunc(ifstream ifile) {
This function is embedded deep within the code. When I am debugging this code with ddd, how can I get the name of the file from the ifstream object. Trying the following:
p ifile or
ptype ifile
leads to a mountain of information being dumped. Is there a way to get the filename that ifile is a stream to?
Thanks,
Sriram.
No way. That’s not possible.
std::ifstreamdoesn’t store the filename, neither does it provide any get function to get the filename. Thus, you cannot get it, given an object of typestd::ifstream.If you really need to know the filename inside the function (and cannot change the function signature), then you can maintain a global lookup table (or preferably
std::map) and add an entry whenever you open a file, something like this: