why won't this code work?

Jul 15, 2010 at 7:43pm
i have tried to create .txt files but the compiler doesn't create them.what am i missing?

#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>


using namespace std;

int main()
{
ofstream myfile;
myfile.open("newfile.txt");
myfile << "this text goes inside\n";
myfile.close();


system("pause");
return 0;
}
Jul 15, 2010 at 8:26pm
The compiler won't create the txt file. You have to run the program. The file will probably be created in the project directory. The location will depend on how you configured your project/workspace.
Jul 15, 2010 at 8:46pm
sorry, i meant run. when i run the script it doesn't create a new file anywhere.
not even in the project folder. another way i know i didn't work is because it
didn't display "enter any key to continue wrote the script in a win32 console.
Jul 15, 2010 at 9:05pm
Are you sure you are running it correctly?
I ran the program and it worked for me.
Jul 15, 2010 at 9:15pm
i opened a new console and it worked in the new one. thanx a lot guys!
Topic archived. No new replies allowed.