error in opening files

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
using namespace std;

#include <iostream>

#include <fstream>
#include <string>

  string filename[9];
  filename[0]="output/prob_search_fail.txt";
  filename[1]="output/prob_download_fail.txt";
  filename[2]="output/avg_download_per_sec.txt";
  filename[3]="output/avg_duration_per_search.txt";
  filename[4]="output/avg_num_copy.txt";
  filename[5]="output/prob_absence_content.txt";
  filename[6]="output/distribution_content.txt";
  filename[7]="output/avg_num_copy_detail.txt";
  filename[8]="output/prob_absence_content_detail.txt";
  
  fstream outfile[9];
  for(int i=0;i<9;i++)
  {
    outfile[i].open(filename[i].c_str(),fstream::out|fstream::app);
    if(!outfile[i].is_open())
    {
      cout<<"open file "<<i<<" error\n";
      exit(1);
    }
  }
  


my error is:open file 0 error
what is wrong with my codes?
Tx!
Do the files exist in the currect directory the program is running in? If you're not sure, try using the full path for one of the filenames.
Topic archived. No new replies allowed.