当我使用时getline,我会输入一串字符串或数字,但我只想让while循环输出"word",如果它不是数字.那么有没有办法检查"word"是否是一个数字?我知道我可以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;
}
}
Run Code Online (Sandbox Code Playgroud)