Where are the files?

Is it possible to create a file using:

ifstream.file("Text.txt");

Will this create a file, or I will have to make a file and then use this command.

I am using Visual C++.

Thanks
Why don't you try it?
Oh I did try it.

1
2
3
4
if (!InpFile) {
		cerr << "Unable to open the file StudentYear2010.txt" << endl;		//show an error if file not found
		exit(1);
	}


I used this code to see if the files opened or not and this error never popped up when I had no pre created file. Doing a windows search also didn't find the file.
Does ifstream.file("Text.txt"); even compile?
If you meant ifstream file("Text.txt"); then it won't create it for you if the file doesn't exist, and your error text should have popped up. If you open it using std::ofstream or with std::fstream with std::ios_base::out flag set, then it should create it.
ofstream and fstream by default have the flag set, just so the OP knows.

http://cplusplus.com/reference/iostream/ofstream/open/
http://cplusplus.com/reference/iostream/fstream/open/

-Albatross
Last edited on
Sorry for the mistake there. I did mean ifstream file("text.txt"); . Thanks I got it now.
OP, you meant ofstream. ifstream is used for reading a file.
Topic archived. No new replies allowed.