Ofstream not working!! :(

It does not overwrite nor create the text file i need, :( pls help.
*C++ is running as admin already*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	ofstream outFile;
	string name;
	double salary;
	  cout<<"Please enter staff Name and Salary: ";
	  cin>>name>>salary;
	outFile.open("salaryOutput.txt");
      if (!outFile)
		  cout<<"Unanble to Open File";
	  else
	  {
		cout<<name<<"     "<<salary<<endl;
	  	outFile<<name<<"     "<<salary<<endl;
		cout<<"DATA SAVED!\n";
		
	  }
	
	outFile.close();
	system("pause");
	return 0;
}
I just tried your code and it does create the file as well overwrites it if run repeatedly.

what do you mean C++ is running in admin mode?
if your built binary is in system path then you need to run your binary as admin/root not C++ compiler.

If you are using Visual Studio then check the path of "Working Directory" under "Debugging" property in the property pages of your project.
Your file will be created in that directory
It says $(ProjectDir) under working directory, what should i change it to?
closed account (E0p9LyTq)
Where files are created or need to be for access by your program depends how you started execution.

If you run from the VS IDE the location of your created file is the solution's directory. The executable is in a sub-directory. The project directory.

If you run the executable directly the created file is in the project directory.

Confusing, I know. But that is how VS works.
Topic archived. No new replies allowed.