im having problems writing numbers to a file

Oct 1, 2013 at 11:00pm
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 Oct 1, 2013 at 11:38pm
Oct 2, 2013 at 12:12am
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.
Oct 2, 2013 at 12:35am
I removed the namefile variable but it still didn't help
Oct 2, 2013 at 12:41am
Remove filterFile.open(a.c_str());
Oct 2, 2013 at 10:37pm
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.