+ 1
does anybody knows how to write output streams to the file?
I need a help... I need to add codes to create an output file and write output streams to the file (“output.txt”). and I need to print the content of “output.txt”. This is my code so far https://code.sololearn.com/cY1XFFSqYAmR any help or idea is great!
1 Resposta
+ 3
There a lot of different variants.. fprintf(), fscanf(), fread(), fwrite(), getc(), putc(), fgetc(), fputc(), fgets(), fputs()...
For example:
#include <iostream>
int main()
{
char text[9]="asdfghjkl";
char symb;
FILE* fp = fopen("text.txt", "a");
FILE* fp2 = fopen("text2.txt", "a");
/*first argument - way to the file, second - read(r), write(w), read+write(a)*/
fputs(text, fp);
//1-what to add in file, 2- ptr to file
/*outputting by char*/
do {
symb=fgetc(fp);
putc(symb, fp2);
}while(symb != EOF);
//u can use it for copying information
fclose(fp);
fclose(fp2);
}