当前位置:网站首页>1. 头文件-注释-命名空间-标准输入输出流
1. 头文件-注释-命名空间-标准输入输出流
2022-07-29 03:33:00 【Timindream】
1. 引入头文件
C++头文件不必是.h结尾,例如C中的math.h,stdio.h在C++中被命名为cmath,cstdio。
#include<cmath>
#include <cstdio>
int main() {
double a=1.2;
a=sin(a);
printf("%lf\n",a);
return 0;
}
2. 注释
除了c的多行注释,c++可以使用单行注释。
/*
多行注释
*/
#include<cmath>
#include <cstdio>
int main() {
double a=1.2; //定义一个变量a并初始化赋值1.2
a=sin(a);
printf("%lf\n",a);
return 0;
}
3. 命令空间
为了防止命名冲突(出现同名),C++引入命名空间,(namespace),通过::运算符限定某个名字属于哪个命名空间。
举例:1班的小明和2班的小明,同名但不属于同一班级。
#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;
}
通常有三种方法使用:
- using namespace X; //引入整个命名空间
- using X::name; //使用单个名字,引入过后之后就用写限定词
- X::name; //程序中加上名字空间前缀,仅引入
4. 输入输出流
cin >> 输入流与cout << 输出流,两者同属于标准命名空间std。
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a;
cout << "Please input a number" << endl; // endl表示换行符,并强制输出
cin >> a;
a = sin(a);
cout << a;
return 0;
}
边栏推荐
- 如何判定是stun协议
- 军品三大基线(功能基线、分配基线、产品基线)及基线包含的文件
- MySQL流程控制之while、repeat、loop循环实例分析
- Makefile details
- Shardingsphere's level table practice (III)
- Understanding of p-type problems, NP problems, NPC problems, and NP hard problems in natural computing
- Violence recursion to dynamic programming 01 (robot movement)
- Rdkit: introduce smiles code, smart code and Morgan fingerprint (ECFP)
- Multi level wavelet CNN for image restoration
- (nowcoder22529c) diner (inclusion exclusion principle + permutation and combination)
猜你喜欢

The Federal Reserve raised interest rates again, Powell "let go of doves" at 75 basis points, and US stocks reveled

Multi level wavelet CNN for image restoration

2022-07-28 study notes of group 4 self-cultivation class (every day)

ROS-Errror:Did you forget to specify generate_ messages(DEPENDENCIES ...)?

暴力递归到动态规划 01 (机器人移动)

(2022杭电多校三)1011-Link is as bear(思维+线性基)

容斥原理

Photo scale correction tool: DxO viewpoint 3 direct mount version

Shardingsphere's level table practice (III)
![[technology 1]](/img/eb/63baf1ae3931a156a0a5b377a9b7d1.jpg)
[technology 1]
随机推荐
three.js 第五十四用如何给shader传递结构体数组
Swing V2: towards a larger model with larger capacity and higher resolution
Design of smoke temperature, humidity and formaldehyde monitoring based on single chip microcomputer
今晚7:30 | 连界、将门、百度、碧桂园创投四位大佬眼中的AI世界,是继续高深还是回归商业本质?...
Realize multi-level linkage through recursion
(nowcoder22529C)dinner(容斥原理+排列组合)
Introduction and advanced level of MySQL (11)
后缀自动机(sam)板子 from jly
Tencent cloud logs in with PEM
腾讯云使用pem登录
Shardingsphere's level table practice (III)
Kubernetes-1.24.x feature
Environment configuration stepping pit during colab use
Summary of SAP localized content in China
Introduction and comparison of unicast, multicast (target broadcast, multicast), broadcast, flooding, flooding
RTP send and receive h265
i. MX 8m plus integrated dedicated neural processing engine (NPU)
(2022杭电多校三)1002-Boss Rush(状压DP+二分)
Does domestic ERP have a chance to beat sap?
Multi level wavelet CNN for image restoration