当前位置:网站首页>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;
}
边栏推荐
- Matlab learning - accumulation of small knowledge points
- Bingbing learning notes: operator overloading -- implementation of date class
- Web uploader cannot upload multiple files
- Simple understanding of CDN, SDN and QoS
- 深入C语言(2)——结构的定义与使用
- How do programmers use code to completely end those things in the system?
- HDU multi School Game 2 1011 DOS card
- Sanzi chess (player + computer)
- 2 neural network toolbox NN
- Machine learning [numpy]
猜你喜欢

Rdkit II: use rdkit screening to screen 2D pharmacophores of chemical small molecules

How does DataGrid export and recover the entire database data, using a single SQL file

(nowcoder22529c) diner (inclusion exclusion principle + permutation and combination)

Photo scale correction tool: DxO viewpoint 3 direct mount version

Reproduce 20 character short domain name bypass and XSS related knowledge points

Exness: dove resolution helped gold rebound, and the focus turned to U.S. GDP

向日葵资深产品总监技术分享:“国民远控”如何在AD域环境下应用

Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping

What have I learned from 200 machine learning tools?

Idea configuration web container and war packaging
随机推荐
再学EXKMP(EXKMP模板)
Simple code implementation of K-means clustering
How to deploy sentinel cluster of redis
深入C语言(3)—— C的输入输出流
今晚7:30 | 连界、将门、百度、碧桂园创投四位大佬眼中的AI世界,是继续高深还是回归商业本质?...
1.6 example: cifar-10 classification
Functions and comparison of repeaters, hubs, bridges, switches and routers
Singleton mode (hungry and lazy)
Sleuth+zipkin to track distributed service links
How close can QA be to business code Direct exposure of defects through codediff
Sanzi chess (player + computer)
Excel拼接数据库语句
数字孪生实际应用案例-智慧能源篇
Flutter 启动白屏
Install the packet capturing certificate
How do programmers use code to completely end those things in the system?
Whole process record of yolov3 target detection
腾讯云使用pem登录
(2022杭电多校三)1002-Boss Rush(状压DP+二分)
Arm architecture and neural network