ofstream stops working mid file



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
47
48
 
ofstream data("character.data");
  data << "health{ ";
  data << maxHealth << " ";
  data << health << " }" << endl;
  bool quit = false;
  data << "attackNames{ ";
  for( int i = 0; true ; i++)
  {

    if( (attack[i].s != "}"))
    {
      data << attack[i].s << " ";
    }
    else
    {
      data << "}" << endl;
      break;
    }
  }
  data << "attackPower{ ";
  for( int i = 0; true ; i++)
  {

    if( (attack[i].s != "}"))
    {
      data << attack[i].x << " ";
    }
    else
    {
      data << "}" << endl;
      break;
    }
  }
  data << "attackCost{ ";
  for( int i = 0; true ; i++)
  {

    if( (attack[i].s != "}"))
    {
      data << attack[i].y << " ";
    }
    else
    {
      data << "}" << endl;
      break;
    }
  }


everything works fine until it gets to data << "attackCost{ "
when i step through with gdb it does show that portion of the code executing exactly as it should, but anything from "attackCost{ " on doesnt show up in the file.

thanks in advance for any help anyone could give me.
Last edited on
It's impossible to tell without knowing the content of attack.
sorry, attack[i].s = slash, then rage, then }
attack[i].y = 0 then 1
.y is an integer member

and i checked with gdb to make sure these are the actual values.

Last edited on
There's nothing obviously wrong with what you've posted.
Did you check the file after data has gone out of scope? Otherwise try flush data to make sure everything you have written to data is written to file.data.flush();
Topic archived. No new replies allowed.