First, the use of C language processing input and output
1. Enter:
In the C language input in the stdin pointer represents the standard input, scanf default reading is stdin point to the input, in ACM we may need to constantly test, it is best to redirect stdin to a file, so it is convenient to debug, use the following methods.
Freopen ("Iniflename", "R", stdin); The function, in turn, specifies the input file, operation mode, directed to the file pointer, so in the following reading, can be read according to SCANF.
The scanf function returns the number of successful reads and returns EOF=-1 if nothing is read. You can use char c = GetChar () when reading a string, and get a character;
Can be used when reading multiple characters, Char s[45]; Get (s); If you read by a space, you can use scanf.
2. Output:
c Use the printf function for output. The function uses the STDOUT pointer as the standard output and redirects the method:
Freopen ("outfile","w", stdout);
Second, C + + processing input and output
1. Enter:
Similar to the C language, C + + defines standard object CIN Reader standard input, cin >> a >> b; The >> operator actually returns a reference to an object, but in the while (CIN >> N), it is converted to the void* type, so it can be used for the judgement of the bool type. Methods for redirecting CIN:
Ifstream ifile ("infilename"*strmin_buf = Cin.rdbuf (Ifile.rdbuf ());
Returns a STREAMBUF pointer to the currently read buffer address.
2. Output:
C + + uses cout output, redirection method:
Ofstream outfile ("outfilename"*strmout_buf = Cout.rdbuf (Outfile.rdbuf ());
Returns a streambuf pointer to the buffer address of the current write.
Basic input and output in Online judge