Estou fazendo alguns testes de manipulação de arquivos .txt sou iniciante e não consigo escrever no arquivo .txt uma variavel do tipo int, tentei de várias formas mas nenhuma funcionou
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace std;
int main() {
FILE *file;
file = fopen("filename.txt", "rt");
char mystring[100];
char name[100];
char sentence [256];
int n;
int teste = 98;
if(file == NULL){
cout << "ERROR 404";
cout << "não achamos o arquivo database.txt";
}
//pegando todas os caracteres do .txt e escrevendo-as
while(fgets(mystring, 100, file) != NULL){
puts(mystring);
}
//escrevendo alguma coisa
printf ("Enter sentence to append: ");
fgets (sentence,256,stdin);
file = fopen ("filename.txt","a");
fputs (sentence,file);
//escrevendo seu nome
for (n=0 ; n<3 ; n++)
{
puts ("please, enter a name: ");
gets (name);
fprintf (file, "Name %d [%-10.10s]\n",n+1,name);
break;
}
fprintf(file, "\nEAE POW \n");
fprintf(file, teste);
}
queria escrever a variável "teste" do tipo int não na tela, mas no arquivo .txt pelo método fprintf();