Writting to file in callback function

Hey everyone! I want to do a basic thing but for some strange reason there is something not working.

I need to write to a file but I'm handling all the code in a callback function, which in turn is declared in a class. Here is the architecture of my code:

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
int main (int argc, char **argv)
{
   
  ImageConverter Aclass;
  while(1); //infinite loop
  return 0;
}
 
class ImageConverter
{
//some variables ..
   
public:
 
ImageConverter ():
  
  {
 
    
 
  }
 
  ~ImageConverter ()
  {
 
  }
 
  void imageCb () //this function gets called when I receive an image frm server
  {
 
    .... //some calculations
     
    fstream outfile ("directory/train.txt");
      
    outfile.open ("directory/train.txt", fstream::in | fstream::out | fstream::app);
     
    outfile<<"P,"<<SomeValues<<endl;
     
    outfile.close();
    
   ....
 
 
  }
 
};



But this doesn't work, the file gets created but it allways overwrites itself which is not what I need to do.

Can anyone please tell me what I am doing wrong? Is it because i am constantly declaring outfile?

Thanks
Topic archived. No new replies allowed.