simple fstream problem

1
2
3
4
5
6
7
8
9
10
11
#include <fstream>
using namespace std;

int main()
{
	fstream ioFile;
	ioFile.open("ioFile.txt", ios::in|ios::out);
	ioFile << "blah blah";
	ioFile.close();
	return 0;
}


I was trying to use code similar to this in my project and it wasn't working. Seeing as how I've never had any experience with fstream, I figured I should try creating a new project utilizing just fstream (eliminate as many possibilities as I can right?). This simple program compiles and runs fine but does not create the file specified. Any ideas why? I'm using VC++ Express as the compiler.

Thanks.
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  fstream myfile ("example.txt", fstream::in | fstream::out | fstream::app);
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}


The file will likly be put in the same folder as your code.
Topic archived. No new replies allowed.