当前位置:网站首页>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;
}
边栏推荐
- A case of gradually analyzing the splitting of classes -- colorful ball collisions
- Makefile details
- How to realize shortcut keys for interface scaling by vscade
- STC MCU drive 1.8 'TFT SPI screen demonstration example (including data package)
- Install the packet capturing certificate
- Practical guidance for interface automation testing (Part I): what preparations should be made for interface automation
- AI_ Drug: VAE of molecular generation model (I)
- ShardingSphere之水平分表实战(三)
- Configure vscade to realize ROS writing
- Environment configuration stepping pit during colab use
猜你喜欢
Sleuth+zipkin to track distributed service links
CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
2022-07-28 study notes of group 4 self-cultivation class (every day)
04 | background login: login method based on account and password (Part 1)
通过递归实现多级联动
Implement Lmax disruptor queue from scratch (VI) analysis of the principle of disruptor solving pseudo sharing and consumers' elegant stopping
Idea configuration web container and war packaging
Matlab learning -- structured programs and user-defined functions
Arm architecture and neural network
MOS管 —— 快速复苏应用笔记(贰)[参数与应用]
随机推荐
CUDA GDB prompt: /tmp/tmpxft**** cudafe1.stub. c: No such file or directory.
Suffix automata (SAM) board from Jly
JS regular expression finds the number of times a character (string) appears (one line of code)
Build redis environment under windows and Linux
Simple code implementation of decision tree
Install the packet capturing certificate
再学EXKMP(EXKMP模板)
Configure vscade to realize ROS writing
暴力递归到动态规划 01 (机器人移动)
How to realize shortcut keys for interface scaling by vscade
军品研制过程-转阶段
最新二开版漫画小说听书三合一完整源码/整合免签接口/搭建教程/带采集接口
[technology 1]
通过递归实现多级联动
安装抓包证书
Introduction and advanced MySQL (XIV)
Naive Bayes -- continuous data
How to deploy sentinel cluster of redis
HDU多校第二场 1011 DOS Card
Introduction to static routing and dynamic routing protocols OSPF and rip and static routing configuration commands