![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
笔记
Del Piero
这个作者很懒,什么都没留下…
展开
-
笔记(关于c++迭代器)
使用迭代器逆序遍历: vector<int> v; for(vector<int>::reverse_iterator it=v.rbegin();it!=v.rend();it++){ printf("%d ",*it); } map的迭代器不同于其他类型的迭代器,没有提供+运算符,因此对map的迭代器it使用it++等操作会出错,可以用下面的写法代替: map<int,int> m; map<int,int>::iterator it=m.begin(原创 2020-10-14 20:34:37 · 110 阅读 · 0 评论 -
笔记(关于stl容器)
在map中,查找可以使用map自带的find(key)方法: map<int,int> m; if(m.find(key)==m.end()) cout<<"不存在值为key的键"<<endl; //查找失败 else{ map<int,int>::iterator it=m.find(key); //查找成功返回迭代器 cout<<it->first<<" "<<it->second<&原创 2020-10-14 10:50:46 · 86 阅读 · 0 评论 -
c++ 字符串与数字的互相转化(二)
字符串转数字:sscanf函数(将字符数组转为数字) char s[10]="123"; int a; sscanf(s,"%d",&a); printf("%d\n",a); //123 char s1[10]="12.3"; double b; sscanf(s1,"%lf",&b); printf("%.1lf\n",b); //12.3 string str="123"; int c; sscanf(str.c_str(),"%d",&c); printf("原创 2020-10-07 11:21:26 · 141 阅读 · 0 评论 -
关于使用string输入输出导致超时
输入时:先按照字符数组用scanf输入,再用string()转为字符串。 char s[maxn]; string str; //cin>>str; //可能会超时 scanf("%s",s); str=string(s); 输出时:使用c_str()方法将字符串转为字符数组,再用printf输出。 //cout<<str<<endl; //可能会超时 printf("%s\n",str.c_str()); 例子:PAT 1047 Student Lis原创 2020-09-28 11:16:36 · 576 阅读 · 0 评论 -
c++ 数字转字符串
利用sstream中的stringstream转换(可以是浮点数) #include <stdio.h> #include <string> #include <iostream> #include <sstream> using namespace std; int main(){ int a=1001; string s; stringstream ss; ss<<a; ss>>s;原创 2020-09-19 11:45:31 · 1298 阅读 · 0 评论