hello i have a big problem with opening files can any body help me with this program
#include "iostream"
#include "fstream"
#include "conio.h"
using namespace std;
int main()
{
ofstream myfile;
myfile.open("example.txt");
myfile<<"Writing on the file";
myfile.close();
getch();
return 0;
}
in this code i expect the following output (Writing on the file)
but after i run the program the output is empty.By empty i mean nothing
and there is no errors what is the problem.
I compiled and ran your program, as is, and found the file, named 'example.txt', complete with the output, "Writing on the file", in the same directory as the source code,.
I use Microsoft Visual Studio 2012 Express. I then use a 'CLR Console Application'. I then copied your program into MS Visual Studio 2008 Express, as a 'WIN32 Console Application', and I still get the text to save, as in the other compiler. So, I'm at a loss as to why you're having difficulties.