I know i can use fstream to create, edit and read files in c++, i also believe there is a different way wich i am unfamiliar with. but is it possible to work with files NOT in the same directory as the program? like if the program is in C:\programfiles but i want it to append something to a file in C:\filesiwanttoalter. or what ever directory??

so

#include <iostream>
#include <fstream>

using namespace std;

Int main () {

ofstream a;
a.open ("C:\programs\fileneedschanges", ios::app);
a << "adding this to end of fileneedschanges";
a.close ();
return 0;
}

would do the trick? i was pretty sure it would not :-) btw why does a.close (); need the "()" when a.open does not??

can you not see the () on open? Its just you have two parameters inbetween them :P

You will need to escape that '\' characters
"C:\\programs\\fileneedschanges"
Then t shold work fine

Chris

Comments
well, it solved my problem
:)

I can't believe i asked that :D of course there is the ( and ) :D thanks

So double slashes? \\ and that's it? does it need a way to see the difference between the folders and the file, or does it just tawke the last one for a file?
EDIT: is cursing allowed in here? if not i am sorry.

aight i've tried it now, as expected it works :D before i mark it as solved though, would you please explain to me why i needs to use double slash?:D

^^will you forgive the question or the swearing when i mark it solved? :P

Sorry I missed the question. '\' is used to escape characters such as '\n' is a newline as you may well no or '\a' is a bleep. Because it's a special escape character in string you must escape it if you wish to use one. Hence the double slash.

Chris

Ahh, that makes sense. i knew about the \n (yeah i know, that makes me a genious ;-) )
but i didn't realise that was it :D well then that was it, thank you for you patience.

This question has already been answered. Start a new discussion instead.