Grammar - C ++ basic grammar

The basic syntax of C ++

head File

In programming competition, we have a common header file:

include <bits/stdc++.h>

C ++ was found that it is partially supported in a nearly universal header file, containing all the available C ++ library function, such as ///.

In the programming contest, use this header file is a good idea, want to reduce the time especially when you are choosing the header file, we are more focused on finding algorithm to solve the problem rather than software engineering. From the perspective of software engineering, we'd better minimize include the header files, if you include some you might not use the header file, the compiler will add unnecessary time and program size.

Shortcoming bits / stdc ++'s

bits / stdc ++. h instead of the standard GNU C ++ library header files, so if you are in some compilers (except GCC) compiler on your code may fail, such as MSVC do not have this header file.
Use it will contain a lot of unnecessary things, and will increase the compile time
part of the C ++ header file is not standard, it is not portable, should be avoided.
Although there are some common standard header files, but still should avoid using it to replace the specific headers, because the compiler are actually read and parse each header file at each compilation contains conversion unit (including recursive comprising header files).
bits / stdc ++ advantage

In the game, the use of this document is a good idea, when you want to reduce waste time to choose the time; especially if your ranking is very time-sensitive time.
This also reduces the preparation of all necessary header files of all chores.
You do not have to remember to use every function of all the STL GNU c ++.

Of course, you can also use #include #include

cin >> scanf () // represents the input

cout << printf () // represents the output

Object Name Belongs to class The corresponding device meaning
China istream keyboard Standard input buffer
cost ostream screen Standard output buffer
Palau ostream screen Standard error output, unbuffered
clog ostream screen Standard error output, a buffer

In C ++ input and output headers iostreami --input input o --output output stream - the stream C language header files to .h suffix, in C ++ header files without suffix.

string.h header file in the C language, C ++ with cstring, math header file in the C language, C ++ header files using cmath.

This is not just a formal change, its implementation is different.

Combined with different functions, the use of different headers

Such as #include

Operators Features
setfill(char c) Set fill character to c represented
setprecision(int n) N represents numerical precision is provided in the
setw(int n) N represents the set domain width

using namespace std;

C ++ standard library and all identifiers defined in a namespace called std, std called standard namespace (standard, standard).

The method of introducing standard namespace: using namespace std;

Note: The semicolon at the end of the statement can not be less

The main function

Primary main () function is a program entry, each application has a main function. The main function returns a value of type int.

int main ()

{

​ cout<<“hello,world!”<<endl;

​ return 0;

}

Note: The end of the program returns 0, endl output here is equivalent to the transport line feed means.

C ++ starts from the main function, is such a general framework.

Some operators

Operators Features
oct Octal format output data
dec Decimal output format data
hex Output data in hexadecimal format
endl Flush the output buffer and line breaks are inserted stream
uppercase Hex output capitalized
skipws Skip Blank output
flush Refresh the stream
left Left
right Align Right
scientific Scientific output record number of law
fixed Way fixed-point output
Shows base Output prefix (0 octal, hexadecimal 0x)
showpoint Output floating decimal point
showpos When the positive integer plus output "+"
发布了34 篇原创文章 · 获赞 2 · 访问量 887

Guess you like

Origin blog.csdn.net/Kapo1/article/details/104002566