Hmm i can't believe I'm having problems with this...
but anyways:
void Tmain_form::write_to_file()
{
ofstream filename("chris.txt"); //opens file chris.txt
filename << "A"; //writes 'A' to chris.txt
filename.close(); //closes file.
}
code above saves the letter 'A' to a file named 'chris.txt'.
But it saves the file 'chris.txt' in the same directory where the .cpp file is saved.
i want to be able to declare the path like below:
void Tmain_form::write_to_file()
{
ofstream filename("c:\program files\chris.txt");
filename << "A";
filename.close();
}
but the above code doesn't work. It just saves in the dir where the .cpp is.... I've also tried:
void Tmain_form::write_to_file()
{
AnsiString path = "c:\program files\chris.txt";
ofstream filename(path);
filename << "A";
filename.close();
}
but i get an error cause i'm guessing the function
ofstream filename();
can't pass an AnsiString variable.. but i tried char and that doesn't work either... anyone help me out with this?