Archived

This topic is now archived and is closed to further replies.

CProgrammer

file_exists(php) for c++?

Recommended Posts

marijnh    182
Not in the standard library.
Look into the boost filesystem library (www.boost.org). It is free and works on a few different platforms. If you only need this to work on one platform use that platform''s methods (win32 api or posix standard).

Share this post


Link to post
Share on other sites
George2    187
quote:
Original post by CProgrammer
Is there an equivalent function to file_exists(php) for c++.

-CProgrammer


fopen can be used to see if a file exists (try to open it read only)

Share this post


Link to post
Share on other sites
CProgrammer    303
quote:
Original post by George2
quote:
Original post by CProgrammer
Is there an equivalent function to file_exists(php) for c++.

-CProgrammer


fopen can be used to see if a file exists (try to open it read only)


Yeah that would work, but I''m using STL(std::ifstream) and it''d be a bit weird to open with fopen then close and open again.
-CProgrammer

Share this post


Link to post
Share on other sites
Krysole    140
Your using std::ifstream aye?

just call open on your ifstream making sure you only have input caps on (ifstream will default to read only which will work i believe), and then check the open and good flags using is_open() and good() respectively.

i think that''ll work anyway

Lorenz (krysole) Pretterhofer
sleep, caffeine for the weak minded

Share this post


Link to post
Share on other sites