files

I am working on a project that requires I write to a file. I followedthe example but I don't know if I need to make a file first.In class the teacher just exicuted this text.Did she have an existing file ?Or,should this module create and open one for me?

void file(void)
{
fstream Acme;
Acme.open("Acme",ios::app);
Acme<<"\n"<<fName<<" "<<lName<<" "<<gCans<<" "<<fCans<<" "<<sCans;
Acme.close();
return;
}
Reported: Incorrect Forum
Yes you do need to make a file. There may be a way to make one but I am not aware of it. It should also be "Acme.txt" in open()

Wrong forum, try beginners next time.
If you try to open a file for writing and it doesn't exist then it automatically creates it.
If you try to open it for reading and it doesn't exist then the "file.isopen()" will return false.

ios::app means that you are gonna write at the end so the file is for writing. You should use "ios::out" also to specify that the file is for output.

It is not neccesary to be "Acme.txt" . It might be a file named "Acme" without any extension.
Last edited on
thank you for the help. I am sorry for posting the wrong area-- I thought I was still in the begginers area.I must have changed out while looking for other posts about files.
Topic archived. No new replies allowed.