用户:
捉虫查看:0 回复:2 评论:0 创建时间:2022-12-15T19:30:19
给你两个数 a和 b,请输出他们的和。 输入格式
一行,两个用空格隔开的整数一个一个和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等等等等等
初学者可以这样想:如果你发现你打的代码没被标粗,你可能要注意了
他有可能会报错
当然,养成习惯根本不用注意