当前位置:网站首页>1. Header file - Comment - namespace - standard input / output stream
1. Header file - Comment - namespace - standard input / output stream
2022-07-29 03:38:00 【Timindream】
1. Import header file
C++ The header file does not have to be .h ending , for example C Medium math.h,stdio.h stay C++ Named cmath,cstdio.
#include<cmath>
#include <cstdio>
int main() {
double a=1.2;
a=sin(a);
printf("%lf\n",a);
return 0;
}
2. notes
except c Multiline comments for ,c++ You can use a single line comment .
/*
Multiline comment
*/
#include<cmath>
#include <cstdio>
int main() {
double a=1.2; // Define a variable a And initialize the assignment 1.2
a=sin(a);
printf("%lf\n",a);
return 0;
}
3. Command space
To prevent naming conflicts ( The same name appears ),C++ Introduce namespace ,(namespace), adopt :: Operator defines which namespace a name belongs to .
give an example :1 Xiao Minghe of class 2 Xiao Ming of Ben , The same name but not belonging to the same class .
#include <cstdio>
namespace f{
int a;
}
namespace s{
int a;
}
int main() {
f::a=2;
s::a=3;
printf("%d\n%d",f::a,s::a);
return 0;
}
There are usually three ways to use :
- using namespace X; // Introduce the entire namespace
- using X::name; // Use a single name , After the introduction, write the qualifier
- X::name; // Add a namespace prefix to the program , Just introduce
4. I / O stream
cin >> Input stream and cout << Output stream , Both belong to the standard namespace std.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a;
cout << "Please input a number" << endl; // endl Represents a newline character , And force output
cin >> a;
a = sin(a);
cout << a;
return 0;
}
边栏推荐
- Introduction to JVM foundation I (memory structure)
- 向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
- Arm architecture and neural network
- Connect with third-party QQ login
- 再学EXKMP(EXKMP模板)
- [technology 1]
- AI_ Drug: VAE of molecular generation model (I)
- 如何判定是stun协议
- 3D advanced renderer: artlandis studio 2021.2 Chinese version
- Matlab learning -- structured programs and user-defined functions
猜你喜欢

【科技1】

数字孪生实际应用案例-智慧能源篇

Rongyun IM & RTC capabilities on new sites

Idea configuration web container and war packaging

Summarize the knowledge points of the ten JVM modules. If you don't believe it, you still don't understand it

NXP i.mx8mp-deepviewrt

Deep into C language (3) -- input and output stream of C

(2022杭电多校三)1002-Boss Rush(状压DP+二分)

Excel splicing database statement

(codeforce547) c-mike and foam
随机推荐
Vs code must know and know 20 shortcut keys!
Naive Bayes -- continuous data
I.MX6U-驱动开发-2-LED驱动
暴力递归到动态规划 01 (机器人移动)
MOS tube - rapid recovery application notes (II) [parameters and applications]
RTP send and receive h265
Deep into C language (1) -- operators and expressions
Machine learning [numpy]
Example analysis of while, repeat and loop loops in MySQL process control
Makefile details
Tencent cloud logs in with PEM
(2022杭电多校三)1011-Link is as bear(思维+线性基)
2022-07-28 study notes of group 4 self-cultivation class (every day)
(nowcoder22529c) diner (inclusion exclusion principle + permutation and combination)
深入C语言(1)——操作符与表达式
(codeforce547) c-mike and foam
Swing V2: towards a larger model with larger capacity and higher resolution
Bingbing learning notes: operator overloading -- implementation of date class
如何判定是stun协议
2 neural network toolbox NN