64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string str="234 567 0abc123 ?789";
istringstream is(str);
int i;
char ch;
cout<<"输出字符串中的数字:"<<endl;
while (is>>ch)
{
if (ch>='0'&&ch<='9')
{
is.putback(ch);//将ch放回到输入流中,这样后面用is>>i可以完整的读入数字
is>>i;
cout<<" i: "<<i<<endl<<endl;
}
}
system("pause");
return 0;
}