#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define bug(a) cout<<"# "<<a<<" ";
#define bug2(a,b) cout<<"# "<<a<<" # "<<b<<endl;
#define bug3(a,b,c) cout<<"# "<<a<<" # "<<b<<" # "<<c<<endl;
void test1() //字符串
{
string s="asdfadsf";
cin>>s;
for(auto ch: s)
bug(ch);
}
void test2() //数组
{
int a[]={1,5,8,7,8,9,8};
for(auto i: a)
cout<<i<<endl;
}
void test3() //stl 容器 vector dequeue
{
vector<int> v={1,5,6,5,8,5};
for(auto& it: v) //在这段程序中,可以返回引用值,通过引用可以修改容器内容 (这个引用我也不知道什么意思,先欠着叭)
bug(it);
cout<<endl;
for(auto it=v.begin();it!=v.end();++it)
bug(*it);
vector<string> v1={"i","like","liu"};
for(auto& it: v1){
//it="c++";
bug(it);
}
}
void test4() //stl map
{
//遍历map返回的是pair变量,不是迭代器
map<int,int> mp;
for(int i=0;i<=10;i++)
{
mp[i]=i+10;
}
for(auto it: mp)
cout<<(it.first)<<"->"<<(it.second)<<endl;
}
int main()
{
//test1();
test2();
//test3();
//test4();
return 0;
}
auto
最新推荐文章于 2024-08-07 13:49:06 发布