Can't print in created .txt file

Hello! This is my first time asking a question here, I don't know if there are any rules about posting, but there goes :

I wrote a function in C++ to create a file and write all information of 'F' gender in a newly created text file by the name of 'Femmes.txt'. The file is created every time I execute the program without any problem, but no matter what I try, nothing seems to be written in the text file (it's always empty).

The code is as follows:

void createFile(Person pers[], int nbPers, const char nameFile[]) {
ofstream create(nameFile, ios::out);
create.setf(ios::fixed);
create.setf(ios::showpoint);

create.open(nameFile);
for (int i = 0; i < nbPers; i++) {
if (pers[i].sex == 'F') {
create << pers[i].sex << setw(8) << pers[i].number
<< setw(11) << setprecision(3) << showpoint
<< pers[i].height << setw(8) << pers[i].weight << endl;
}
}
create.close();
}

int main (){
createFile(pers, nbPers, "Femmes.txt");

system("PAUSE");
return 0;
}

Please enlighten me, thank you very much!
The code to write your array to the file seems to be ok as far as I can tell from the snippet you provided.
Are you sure that your array contains any data?
Maybe you can post the whole code.
Topic archived. No new replies allowed.