猫史档案馆


c++教程1【a+b】

用户:捉虫捉虫查看:0 回复:2 评论:0 创建时间:2022-12-15T19:30:19


给你两个数 ab,请输出他们的和。 输入格式

一行,两个用空格隔开的整数一个一个bb

输出格式

一个整数,表示A+B

#include<bits/stdc++.h>//头文件
using namespace std;//使用标准命名空间
int main(){
	int a,b;//取整函数,范围[-2^31~2^31-1]
	cin>>a>>b;//输入
	cout<<a+b;//输出
	return 0;
}

其中头文件不一定是<bits/stdc++.h>,这里提供几个常用的



#include <algorithm>    //STL通用算法
#include <bitset>     //STL位集容器
#include <complex>     //复数类
#include <deque>      //STL双端队列容器
#include <exception>    //异常处理类
#include <functional>   //STL定义运算函数(代替运算符)
#include <list>      //STL线性列表容器
#include <map>       //STL 映射容器
#include <ios>      //基本输入/输出支持
#include<iosfwd>     //输入/输出系统使用的前置声明
#include <iostream>
#include <istream>     //基本输入流
#include <ostream>     //基本输出流
#include <queue>      //STL队列容器
#include <set>       //STL 集合容器
#include <sstream>    //基于字符串的流
#include <stack>      //STL堆栈容器    
#include <stdexcept>    //标准异常类
#include <streambuf>   //底层输入/输出支持
#include <string>     //字符串类
#include <utility>     //STL通用模板类
#include <vector>     //STL动态数组容器

不一定要写 using namespace std

也可以这样:但是麻烦

#include<bits/stdc++.h>//头文件
int main(){
	int a,b;//取整函数,范围[-2^31~2^31-1]
	std::cin>>a>>b;//输入
	std::cout<<a+b;//输出
	return 0;
}

同时,我们也发现,没被标粗(就是那些黑体字)的符号正是std所需

如:int,renturn,还有以后的long,for,if,while,break,max,time等等等等等

初学者可以这样想:如果你发现你打的代码没被标粗,你可能要注意了

他有可能会报错

当然,养成习惯根本不用注意


回复

上一页1 页 / 共 1下一页
捉虫捉虫

这个教程不是给初学者的,

而是给有一定基础却不会注释代码的人的

初学者建议去看语法,然后搞逻辑

我的教程会在逻辑上出难题

点赞1


评论


SunSetSunSet

我觉得a+b不用万能头了吧,用iostream应该好点

点赞0


评论