Posição do ponteiro em arquivos c++
A função a seguir deveria colocar o ponteiro na décima posição no aquivo e escrever a partir dele, porém isto não ocorre, alguém para me ajudar?
void EstagioAluno::writeEA (ofstream &arq)
{
char buffer [1000];
char aux [20];
short length;
itoa(matricula, buffer, 10);
strcat(buffer, "|");
strcat(buffer, nomeCompleto);
strcat(buffer, "|");
strcat(buffer, tipoEstagio);
strcat(buffer, "|");
strcat(buffer, nomeEmpresa);
strcat(buffer, "|");
strcat(buffer, cnpj);
strcat(buffer, "|");
strcat(buffer, nomeSupervisor);
strcat(buffer, "|");
strcat(buffer, dataInicio);
strcat(buffer, "|");
strcat(buffer, dataFim);
strcat(buffer, "|");
strcat(buffer, dataEntregaRelatorioParcial);
strcat(buffer, "|");
strcat(buffer, situacao);
strcat(buffer, "|");
itoa(horasPrevistas, aux, 10);//converte int em char na base 10 e passa para aux
strcat(buffer, aux);
strcat(buffer, "|");
itoa(horasTotalizadas, aux, 10);//converte int em char na base 10 e passa para aux
strcat(buffer, aux);
strcat(buffer, "|");
strcat(buffer, parecerFinal);
strcat(buffer, "|");
length = (short) strlen(buffer);
arq.seekp(9, ios::end);//reserva os 10 primeiros bytes para o cabeçalho
cout << arq.tellp() << endl;
cout << buffer << endl;
//campo flag de excluido (avail list)
arq.write((char*)&length, sizeof(length));
arq.write(buffer, length);
cout << arq.tellp() << endl;
}
e dessa forma eu abro o arquivo na main e passo para a função:
case 1:
arq1.open ("estagios.txt", ios::binary|ios::app);
if (!arq1.good())
{
cerr<< "Não foi possível abrir o arquivo."<<endl;
exit(1);
}
ea.PreencherEA();
ea.writeEA(arq1);
arq1.close();
break;Discussão (0)
Carregando comentários...