file wont print out

Nov 19, 2014 at 1:25am
How come when i open the file output nothing is there?
1
2
3
4
5
6
7
8
9
10
11
12
13
 file.close();
 
    fstream output;
    output.open("Output.txt");
    output << (people-count) << endl;
    for (int j = 0; j < (people-count); j++)
    {
        
       
        if(records[j].isdeleted==true)
        output << records[j].iD << " " << records[j].firstName << " " << records[j].lastName << " " << records[j].examGrade;
        
    }
Nov 19, 2014 at 3:15am
first, i wouldnt use fstream... second, records[j].isDeleted == true is redundant. why not just make it records[j].isDeleted. third, we need more code. how else can we know from so little information?
Nov 19, 2014 at 3:16am
First of all, you should ALWAYS test the stream first:
1
2
3
4
5
if(!output)
{
cerr << "Could not open file to write to";
return -1;
}

or similar.

Then, I would step through your program with the debugger to see what's happening. It's possible your if statement in the for loop never evaluates to true.
Last edited on Nov 19, 2014 at 3:16am
Topic archived. No new replies allowed.