Yunus 0 Posted June 30, 2016 Report Share Posted June 30, 2016 Boa noite Srs, eu criei um buffer para escrever um registro em um arquivo e preciso de passar um inteiro para uma string (vetor de char), como faria isso? segue o código: void writeEA (ostream &stream, EstagioAluno &ea) { char buffer [1000]; short length; strcpy (buffer, ea.matricula); strcat(buffer, '|'); strcat(buffer, ea.nomeCompleto); strcat(buffer, '|'); strcat(buffer, ea.tipoEstagio); strcat(buffer, '|'); strcat(buffer, ea.nomeEmpresa); strcat(buffer, '|'); strcat(buffer, ea.cnpj); strcat(buffer, '|'); strcat(buffer, ea.nomeSupervisor); strcat(buffer, '|'); strcat(buffer, ea.dataInicio); strcat(buffer, '|'); strcat(buffer, ea.dataFim); strcat(buffer, '|'); strcat(buffer, ea.dataEntregaRelatorioParcial); strcat(buffer, ea.situacao); strcat(buffer, '|'); strcat(buffer, ea.horasPrevistas); strcat(buffer, '|'); strcat(buffer, ea.horasTotalizadas); strcat(buffer, '|'); strcat(buffer, ea.parecerFinal); strcat(buffer, '|'); length = (short) strlen(buffer); stream.write(&length, sizeof(length)); stream.write(buffer, length); }[\code] Os campos matricula, horasPrevistas e horasTotalizadas são int, consequentemente o strcpy não funciona, o que colocaria no lugar? desde já agradeço! Quote Link to post Share on other sites
0 vangodp 0 Posted June 30, 2016 Report Share Posted June 30, 2016 use sprintf. é como o printf porem em vez da saida ser na tela você precisa indicar o buffer onde você quer guardar o resultado. sprintf == string print format ah! e tambem existe outra chamada fprintf, a saida dessa é direta ao arquivo. fprintf == file print format Quote Link to post Share on other sites
Question
Yunus 0
Boa noite Srs,
eu criei um buffer para escrever um registro em um arquivo e preciso de passar um inteiro para uma string (vetor de char), como faria isso?
segue o código:
Os campos matricula, horasPrevistas e horasTotalizadas são int, consequentemente o strcpy não funciona, o que colocaria no lugar?
desde já agradeço!
Link to post
Share on other sites
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.