标签:sscanf mes space ++ string har printf %s ace
方法一:
1 #include<sstream> 2 #include<iostream> 3 using namespace std; 4 5 int main() { 6 stringstream ss; 7 int n; 8 string s; 9 cin>>n; 10 ss<<n; 11 ss>>s; 12 cout<<s<<endl; 13 ss.clear();//重置流的状态 14 cin>>s; 15 ss<<s; 16 ss>>n; 17 cout<<n<<endl; 18 }
方法二:
#include<cstdio> int main() { char s[10]; scanf("%s",s); int n; sscanf(s,"%d",&n); //把s以%d写入n printf("%d\n",n); n++; sprintf(s,"%d",n); //把n以%s形写入s printf("%s",s); return 0; }
标签:sscanf mes space ++ string har printf %s ace
原文地址:https://www.cnblogs.com/ACMerszl/p/10376684.html