2.4.3 64-bit integer
Input output long Long in addition to Cin,cout, the printf and scanf statements can also be used, but the corresponding placeholder missing is the peace table associated with the compiler: In Linux, GCC is very agreeable to the use of%lld; in Windows, MinGW gcc and VC6 all need to use%I64D, but VS2008 is%lld.
2.4.4 input and output in C + +
The problem is the classic "a+b" problem: Enter several pairs of integers and output each pair.
The 1th method:
#include <cstdio>//the function is close to the stdio.h in C, but some are different .using namespacestd;intMain () {intA, B; while(SCANF ("%d%d", &a, &b) = =2) printf ("%d\n", A +b); return 0;}
To use a C language header file in a C + + program, remove the extension. h and precede it with the lowercase c. For example, the new name of stdio.h in C + + is Cstdio. In addition, the first line in//begins with the C + + specific "single-line comment," which can be mixed with the traditional comments in C (/* and */).
It is necessary to note that C + + has a common header file that is used in the language. If you prefer, you can continue to use stdio.h and omit the using namespace STD statement. In fact, many, but not all, C programs can be compiled without modification by the C + + compiler.
The 2nd method:
#include <iostream>usingnamespace std; int Main () { int A, b; while (Cin >> a >> b) " \ n " ; return 0 ;}
The header file iostream contains definitions for the input and output streams.
The 2nd method can also be modified into a file input and output stream. Of course, you can also redirect files with Freopen, but the more orthodox approach is as follows:
#include <fstream>using namespacestd;ifstream Fin ("aplusb.in"); Ofstream Fout ("Aplusb.out");intMain () {intA, B; while(Fin >> a >>b) Fout<< A + b <<"\ n"; return 0;}
If you want to use CIN and cout again, simply remove the statement for Fin and fout and add two lines to it:
#define fin cin#define Fout cout
Compare efficiency (using clock () and clocks_per_sec)
Introduction to Algorithmic Competition learning note 2.4.4 input and output in C + +