网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b<<endl;
return 0;
}
// 输出结果:
7 9
16
Process returned 0 (0x0) execution time : 3.375 s
Press any key to continue.
2.有多组测试数据,直到读至输入文件结尾为止
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)
{
cout<<a+b<<endl;
}
return 0;
}
// 输出结果:
7 9
16
4 9
13
4 9
13
1 6
7
3.在开始的时候输入一个N,接下来是N组数据
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,T;
cin>>T;
while(T–)
{
cin>>a>>b;
cout<<a+b<<endl;
}
return 0;
}
// 输出结果:
3
4 9
13
1 3
4
1 8
9
Process returned 0 (0x0) execution time : 10.708 s
Press any key to continue.
4.输入不说明有多少组数据,但以某个特殊输入为结束标志
- 假设以a或者b为零 结束
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b)
{
if(a0||b0)
break;
else
cout<<a+b<<endl;
}
return 0;
}
// 输出结果:
2 3
5
4 9
13
0 6
Process returned 0 (0x0) execution time : 7.490 s
Press any key to continue.
5.读入字符
使用getchar()
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a;
while((a=getchar())!=EOF)
{
cout<<a;
}
return 0;
}
// 输出结果:
4
4
d
d
9
9
l
l
---------------------------------------------------------------------
PS:可能有很多朋友分不清楚get,gets,getline,cin.get的细微区别这里我就不总结了,我直接上链接了这个大佬确实写的不错:点它就完事了,这是一个传送门。
----------------------------------------------------------------------------
6. 读入字符使用cin.get
#include<bits/stdc++.h>
using namespace std;
int main()
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-oDP5yM2V-1715622140307)]
[外链图片转存中…(img-NZtfuPrS-1715622140308)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!