File output crash

I am currently making a genetic algorithm, and once I got that working I started creating a program to optimize the variables (like mutation rate and population size). Everything was going fine, but it is now crashing upon outputting to a file. Here is the snippet of optimization code which creates the file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ofstream _OutputFile; // the file to output debug shit to

  {
    time_t t        = time(0);
    struct tm* now  = localtime(&t);
    string date = "";
    stringstream out;

    system("mkdir data"); // not planning on cross-platform, no need to get complicated
    system("cls");

    out << "data/" << (now->tm_year + 1900) << "." << (now->tm_mon + 1) << "." << (now->tm_mday) << "." <<
         (now->tm_hour) << "." << (now->tm_min) << "." << (now->tm_sec) << ".csv";
    date = out.str();
    _OutputFile.open(date.c_str());
  }

  if(!_OutputFile.good() || _OutputFile.bad())
  {
    cout << "crap. The file is not good" << endl;
    system("pause");
  }


Notes: The brackets around the file creation are just for scope. I am almost positive they do not affect anything. The if statement below that is always false, it never triggers. All of the code before the opening of the file just makes the name have the timestamp like 2012.11.17.1.51.57.csv.

Here is the code where it segfaults:
1
2
3
4
5
6
7
// Time for some csv magic!
  _OutputFile << "Population Size" << endl;
  _OutputFile << "Value,Avg Generations,Success rate" << endl;

  for(int i = 0; i < 25; i = i + 1) // example output: 70,300,0.43
    _OutputFile << PopulationSizeResults[i].independantValue << "," << PopulationSizeResults[i].avgGenerations <<
                   "," << PopulationSizeResults[i].successRate << endl;


it segfaults at the _OutputFile << "Population Size" << endl; line, and when that is commented out, it segfaults at the following line.

More info:
Using Code::Blocks.
Debugger Log:
Program received signal SIGSEGV, Segmentation fault.
In std::ostream::sentry::sentry () ()


The four callstacks:
Nr Address Function
0 00000000 0x0044a102 in std::ostream::sentry::sentry()
1 00000000 0x00471e23 in std::__ostream_insert<char, std::char_traits<char> >()
2 00000000 0x0047505c in std::operator<< <std::char_traits<char> >()
3 004035CF main()


If you want to see the entire program, you can find it at my git: https://github.com/LNunley/Optimization3/tree/Code-Replacement-
Make sure to use the Code-Replacement- branch

Thank you for your help!
1
2
3
4
5
6
//main.cpp: line 60
  Results PopulationSizeResults[25];
  for(int i = 0; i < 51; i = i + 2)
  {
    PopulationSizeResults[i / 2] = //...
  }

You are accessing the array out of bounds.
That was it, thank you!
Topic archived. No new replies allowed.