函数:
stoi(string s);//将字符串转换为数字,只能转换为int
to_string (int t)//将数字转换为字符串
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t1,t2;
string s1,s2;
t1=135;
s2="378";
t2=stoi(s2);//字符串转数字
s1=to_string(t1);//数字转字符串
cout<<s1<<endl<<t2<<endl;
return 0;
}
流 stringstream
//找n以内的数中,有数字d出现的数的个数
#include <bits/stdc++.h>
using namespace std;
const int N=5005;
int main()
{
int n,d;
cin>>n>>d;
int ans=0;
string s2;
stringstream ls;
ls.clear();//
ls<<d;//将数字转换成流
ls>>s2;//将流转换成字符串
for(int i=1;i<=n;i++)
{
stringstream ls;
string s1;
ls.clear();
ls<<i;
ls>>s1;
if(s1.find(s2)==string::npos)
{//s1.find(s2):在s1中找字符串s2第一次出现的位置,找到后返回下标
//找不到返回string::npos(string 中定义的静态常量)
ans++;
}
}
cout<<ans;
return 0;
}