#include <iostream>
using namespace std;
char GetChar(istream&in=cin)
{
char ch;
while((ch=cin.get())==' '&&in.peek()!=EOF)
;
return ch;
}
int main()
{
char ch;
char x;
ch=GetChar();
while(ch!='\n'&&ch!=EOF)
{
if(ch>='0'&&ch<='9')
{
cin.putback('m');
cin>>x;//相当于使输入的x=‘m’
cout<<x<<" ";
}else
{
cout<<"出现非法字符"<<endl;
exit(1);
}
ch=GetChar();
}
cout<<endl;
system("PAUSE");
return 0;
}
putback()
最新推荐文章于 2021-04-16 09:33:50 发布