dirent.h

Mar 15, 2010 at 7:07pm
Hey, this isn't exactly an end of the world problem more a comfort issue. I've been using dirent.h recently and its been written for C as oppose for C++. So for outputting statements I'm having to use printf() etc and for someone who never initially learned C i much prefer the std::cout syntax. My question is, can I overload the insertion operators to use std::cout << instead of printf()?
Mar 15, 2010 at 9:51pm
Anywhere you can use printf you can use << .
What exactly are you printing?
Mar 16, 2010 at 10:03pm
Yeah that's what I thought, but when I tried to ouput a CString member of an object of type DIR I was getting an error not being able to do something or other. On second attmept it works fine though. Must have not been concentrating or something!
Mar 16, 2010 at 11:45pm
Ok scrap what I just said, I've got it again. This is pretty much what i'm doing:

1
2
3
DIR *ptrDir = NULL;
ptrDir = opendir(".");
std::cout << ptrDir->current << "> ";


Error:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'dirent' (or there is no acceptable conversion)
Mar 17, 2010 at 6:46am
That because the current member of the DIR struct is a structure itself.
You need the d_name member of the current structure.

Look at the dirent.h file
Mar 17, 2010 at 10:00am
Thanks, I overlooked that structure and was just focusing on the DIR and dirent structures.
Topic archived. No new replies allowed.