im having problems writing numbers to a file

I have been trying to get the program to write some double values to a file. it creates the file but the file remains blank. if anyone could give me some guidance on this you may just save me from insanity. ty in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 void cRCFilter::openFilterFile(string a)  // opens and stores data in a file named by user
{
	double fResistor = R.getResistor();
	double fCapacitor = C.getCapacitor();
	double fRtol = R.getTolerance();
	double fCtol = C.getTolerance();

	ofstream filterFile(a.c_str());
	nameFile = a;
	filterFile.open(a.c_str());
	filterFile << fResistor << endl
				<< fRtol << endl
				<< fCapacitor << endl
				<< fCtol << endl
				<< choiceF << endl
				<< nameFile << endl; 

	filterFile.close();
}
Last edited on
Remove line 16. You are opening the same file twice. The constructor has opened the file already and then on 16 you open it again. It's only the second file that is written to and when the first file closes it truncates the second leaving you with an empty file.
I removed the namefile variable but it still didn't help
Remove filterFile.open(a.c_str());
you are awesome ty so much i have been struggling with that forever. it works great ty ty ty.
Topic archived. No new replies allowed.