當我使用時getline,我會輸入一串字符串或數字,但是如果它不是數字,我只希望while循環輸出“單詞”。那么,有什么方法可以檢查“單詞”是否為數字?我知道我可以atoi()用于C字符串,但是對于字符串類的字符串呢?int main () { stringstream ss (stringstream::in | stringstream::out); string word; string str; getline(cin,str); ss<<str; while(ss>>word) { //if( ) cout<<word<<endl; }}
- 3 回答
- 0 關注
- 426 瀏覽
添加回答
舉報
0/150
提交
取消