Sign in to follow this  

handeling files etc in c++

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I do stuff with the filesystem in c++? eg copy files, move files, check if a file exists, get a list of files in a directory, find the temp directory, find the working directory, fiond my documents etc? I'm sure one of the many headers that came with vs2008 has basic functions like that but I can't seem to find it...

Share this post


Link to post
Share on other sites
The last post was correct you can use the std::fstream along with the header file of #include <fstream> to access and write files that are and are not in your programs directory however you need to know where those files are.

If you want the user to be able to pick one there is a win32 api that useing a dialog box to let the user select a file.

[source lang"cpp"]
// a quick example
#include <fstream>

int main()
{
std::fstream File;
File.open("Test.txt",std::ios::in); //use std::ios::out to do ouputing to files
if(!File){std::cout<<"Error no file to load\n"; return 0;}
char Buffer[250];
File >>Buffer;
std::cout <<Buffer;

File.close();

return 0;
}




Ok thats basicaly how to read from a file one line at a time this code snippet only reads one line google fstream and you will learn more now you will not that most pepole would say i have a bug cause i use char but to use the >> operators it only returns to a char arry for the most part.

however doing useing char can be dangoures because of buffer overflows so check out about useing fstream with std::string

Regards Joue.

Share this post


Link to post
Share on other sites
Now ive got my grafics sorted and I went to do this today. I want to use the boost filesystem but ran into a few problems.

It would semm boost doesn't support visual studio 2008. I went through some of the files to make it see "MSC_VER 1500" as a valid compiler version but now it just says "LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc80-mt-gd-1_34_1.lib'" instead... Am I just going to wait untill they update boost to work for the 2008 compiler? (9.0?)

Share this post


Link to post
Share on other sites

This topic is 3585 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this