Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

handeling files etc in c++

This topic is 3890 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
Advertisement
You can use files in your program using the I/0 system, the fstream library will give you the ability to read and write files.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!