Saving files in txt with c ++

0

I am trying to create a program that saves the hashed stored data in 4 different txt files, as it is the hash index it chooses the file it should save.

example:

hash índice 0 = txt_0.txt
hash índice 1 = txt_1.txt
hash índice 2 = txt_2.txt
hash índice 3 = txt_3.txt

So I created a for that runs all my list, and I created a literator to be able to rescue the data of the list and save in txt, the problem and that it only saves if I register one after saved, if register 2 it only saves the last one registered.

void func_arquivo::cria_arquivo(int código, int idade, string nome, int     indice){
ofstream arquivo;
for(int i=0;i<TAM;i++){
    char nome_arquivo[FILENAME_MAX];//usado para que a função consiga escrever todos os nomes dentro do char se nao ele nao comporta
    sprintf(nome_arquivo, "Data-%d.txt",i);//função que realiza conversao de inteiros para char
    arquivo.open(nome_arquivo, ios::app);

    if(indice == i){
        arquivo << codigo << "\t" << idade << "\t" <<  nome << "\n";
    }
    arquivo.close();
 }
}

This is the code that writes in txt.

What will happen?

I'm kind of lost with this.

    
asked by anonymous 28.10.2016 / 14:36

0 answers