#13315: string轉int


d10631324@gapps.fg.tp.edu.tw (沙門氏菌)


#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;
int main()
{
string s;
stringstream ss;
int x;
while(cin>>s)
{
reverse(s.begin(),s.end());
ss<<s;
ss>>x;
cout<<x<<endl;
ss.str("");
ss.clear();
}
return 0;
}

錯了幾次才看懂,題目的意思是

1230>>321   0000>>0 001230>>32100

希望不要有人跟我一樣蠢蠢的消錯零QQ

#13331: Re:string轉int


ysh58168@gmail.com (楊昊天)


#include
#include
#include
#include
using namespace std;
int main()
{
string s;
stringstream ss;
int x;
while(cin>>s)
{
reverse(s.begin(),s.end());
ss<<s;
ss>>x;
cout<<x<<endl;
ss.str("");
ss.clear();
}
return 0;
}

錯了幾次才看懂,題目的意思是

1230>>321   0000>>0 001230>>32100

希望不要有人跟我一樣蠢蠢的消錯零QQ


你好,可以請教一下,為甚麼原本是00250,轉換後會變成5200?

經過stringstream會把尾數為0的字元刪除嗎??

謝謝!!