(i) standard input and output:
printf ("%d", n);
scanf ("%d", &n);
(ii) file input and output:
fprintf (FIN, "%d", n);/FILE *fin = open ("In.txt", "RB");
FSCANF (Fout, "%d", &n);/FILE *fout = open ("OUT.txt", "WB");
(iii) input and output redirection:
1.freopen ("In.txt", "RB", stdin);
Freopen ("Outin.txt", "WB", stdout);
In C, the use of scanf () and printf () is read and stored from the file
In C + +, the use of CIN and cout is read and stored from the file
2. The standard file input and output in C + + is:
#include <fstream>
using namespace Std;
Ifstream fin ("in.txt");
Ofstream fout ("OUT.txt");
fin>>a>>b;
fout<<a<<b;
(iv) Input output in string
sprintf (CH, "%d", a);/char Ch[max] to ensure that the CH array is large enough
SSCANF (CH, "%d", &a);
(v) Other
(1) fgetc (Fin);//fin is a file pointer
Function: Reads a character from a file and returns an integer
(2) GetChar ();
Function: read a character from standard input, similar to fgetc, but with different input methods.
(3) fgets (CH, MAXN, Fin),//char Ch[max], MAXN read no more than MAXN-1 characters, and then end with a Terminator ' "; FILE *fin;
Function: Read the complete line from the file and read the "\ n" End of the return character.
can also be used as a keyboard input: fgets (Ch,n,stdin); The advantage of using this is to read data of a specified size, avoiding cache overflow problems caused by the gets function receiving a string from stdin without checking the volume of the cache it replicates
(4) gets (CH);//char Ch[max];
Function: Reads a line of strings from the standard input output, can read spaces and TEB, and reads to the carriage return ' \ n ' end. But it does not limit the number of inputs, so it is easy to buffer overflow, not recommended.