fstream issue...

closed account (jLNv0pDG)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
	fstream myfile;
	myfile.open ("test.txt");
	if (myfile.is_open()) {
		cout << "opened!\n";}
	else {
		cout << "failed!\n";}
return 0;
}
failed!


Code based on: http://www.cplusplus.com/reference/iostream/fstream/is_open/

Is there something wrong with my fstream constructor or calling myfile.open?

I usually just use ofstream, but plain fstream inherits more functions from both input and output so seems more useful.
Last edited on
If you want to use the file for output and you want to create the file if it doesn't exist use
myfile.open ("test.txt",ios::out); when you open the file.
Last edited on
Topic archived. No new replies allowed.