Trouble writing to a .txt file

I have to write out to a text file using a for loop. The file is being created, but there is no data in the file when I open it. Here's what I've got (assuming f1=10, f2=10, and samperiod = .025)

#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;


void GenerateTone (double f1, double f2, double dur, double samperiod)
double tone;
ofstream outfile;"OutputTone.txt");

for (dur = 0; dur >= .5; dur = dur + samperiod)
tone = (sin(2*M_PI*f1*dur))+(sin(2*M_PI*f2*dur));
outfile << dur << " " << tone << endl;

I'm not sure what the problem is, maybe something with the sin()?


It's your loop. You initialise dur to zero then tell the loop to run while dur is greater or equal to 0.5. Therefore, the loop never runs.
pfff derp. Thanks.
Topic archived. No new replies allowed.