随笔-2  评论-1  文章-1  trackbacks-0

istream::operator >>
istream& operator >>( char* psz );

istream& operator >>( unsigned char* pusz );

istream& operator >>( signed char* pssz );

istream& operator >>( char& rch );

istream& operator >>( unsigned char& ruch );

istream& operator >>( signed char& rsch );

istream& operator >>( short& s );

istream& operator >>( unsigned short& us );

istream& operator >>( int& n );

istream& operator >>( unsigned int& un );

istream& operator >>( long& l );

istream& operator >>( unsigned long& ul );

istream& operator >>( float& f );

istream& operator >>( double& d );

istream& operator >>( long double& ld ); (16-bit only)

istream& operator >>( streambuf* psb );

istream& operator >>( istream& (*fcn)(istream&) );

istream& operator >>( ios& (*fcn)(ios&) );

这些是本来>>支持的类型。
对于cin来说,如cin>>(int)a,而输入一字符串,则会使cin陷入错误状态,故在输入之前应该先检查if(isdigit(a))。

posted on 2006-06-27 21:34 栗子 阅读(452) 评论(1)  编辑 收藏 引用 所属分类: 学习有感

评论:
# re: 重载输入符<< 2006-06-28 09:00 | 栗子
cin陷入错误后,可以用
cin.clear() 来使cin输入流恢复正确的状态。但是,被存在缓存中的数据还是-1,所以要清空缓存。利用fflush(stdin)(只适用于VC6)。  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理