1.Ostream & operator <(int );
The <symbol is overloaded for int type output. Why is ostream reference returned?
For example:
Cout <"1122" <"2345" <endl;
When "1122" is output, cout is returned, that is, cout <"1122" is returned as cout, and then it can continue like cout <"2345" <endl; output in this way.
2.Output of arrays and pointers
Ostream can output the following pointer types:
Const signed char *
Const unsigned char *
Const char *
Void * // The numeric representation of the printed Address
Eg:
Char a [] = "sdwadwada" // The int type cannot be printed so intelligently on the char array cout <a <endl; // display: sdwadwadachar * a = "sdwadwada" cout <a <endl; // sdwadwadacacut <& a <endl; // print the address cout <(void *) a <endl; // print the address
3.
Std: cout. put (66.5); // B
Std: cout. put (65); //
Return 0;
4.Forced conversion
Long val = 560031841;
Cout. write (char *) & val, sizeof (long); // display data in 4 characters
Void main () {char ch; while (cin. get (ch) {cout <ch <"";}}
Version 3:
Char ch;
Ch = cin. get ();
While (ch! = '\ N ')
{
Cout <ch <""
Ch = cin. get ();
}
After the end of the file is reached, cin. get (void) returns the EOF value. Therefore, you can read the input as follows:
Declare the ch type as int rather than char, because the value EOF may not be represented by the char type.
The above experiment results can be obtained:
1. The cin indeed skips the blank space, and the terminator also skips into an infinite loop.
8. File Input and Output
8.1Header file: fstream
The file contains the iostream file automatically, so you do not need to display the header file containing the iostream.
Ostream is the base class of ofstream, and istream is the same. Therefore, all ostream methods can be used, including insertion operator definition, formatting method, and control operator.
Eg:
Ifstream fin (".....txt ");
Char ch;
While (fin. get (ch) // The method is the same as that of cin.
{
....
}
If (! Fin. is_open ())
{
...
}
8.2Open multiple files
Cin. clear () can also be avoided, depending on the situation.
Command Line Processing: