Using >> and fprintf to access same file while open

Is it possible to use >> and fprintf to access the same file? The fstream is passed to a function. I use outFile >> to write to it. Then I want to use fprint to write to it. I do this because the formatting I created originally to screen and looking for a quick convert. Not too familiar with printf cmds. Not sure why the fprint will not write to file, cuz it's open already?

1
2
3
//files to be read and written
   fstream fsInputFile,
           outFile;

The function call:
 
printCompleteList(outFile, completeListQ);

The function:
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
29
30
void printCompleteList(fstream & outFile, linkedQueueType<FlightRecord> completeList)
{
   FlightRecord tempRecord;
   
   FILE * pFile;
   pFile = fopen ("lab7.txt","w"); //ALREADY OPEN, IS PASSED IN
                                   //ANY OTHER WAY TO DO THIS?
   
   //print heading
   outFile << fixed << right
           << setw(11) << "DESTINATION"
           << setw(10) << "FLIGHT #"
           << setw(11) << "ARRIVAL\n\n";
   
   while ( !completeList.isEmptyQueue() )
   {
      //pull first record from queue
      tempRecord = completeList.front(); 
      
      //print data from Record
      outFile << fixed << right 
              << setw(6) << tempRecord.range
              << setw(12) << tempRecord.flightNum
              << "\t";
      fprintf (pFile, "%02d:%02d\n",tempRecord.arrivalHour,tempRecord.arrivalMinute); //NOT WRITING to file
      
      //delete front queue
      completeList.deleteQueue();
   }     
}
Found the perfect solution in one line of code that redirects all output without changing cout or printf to anything. The freopen function, see link:

http://www.cplusplus.com/reference/clibrary/cstdio/freopen/
Topic archived. No new replies allowed.