STL之--输入输出流状态的相关函数操作
2016-10-06 18:26
260 查看
clear()函数
功能:更改cin的状态标识符,使之处于正确状态。
定义在
ignore()函数
功能:ignore函数是输入流的成员函数,可用来读取并抛弃残留在流缓冲区中的包括‘\n’在内的字符。
定义在
其中,
system()系列函数
1.system(“pause>nul”)
用于在输出时,等按下任意键后才会返回,且不显示”请按任意键继续”;
2.system(“pause”)
用于在输出时,等按下任意键后才会返回;
3.system(“cls”)
可以实现清屏操作
功能:更改cin的状态标识符,使之处于正确状态。
定义在
<ios>头文件中,是basic_ios类的成员函数,以下是相关的源码:
// TEMPLATE CLASS basic_ios template<class _Elem,class _Traits> class basic_ios: public ios_base { // base class for basic_istream/basic_ostream public: typedef basic_ios<_Elem, _Traits> _Myt; typedef basic_ostream<_Elem, _Traits> _Myos; typedef basic_streambuf<_Elem, _Traits> _Mysb; typedef ctype<_Elem> _Ctype; typedef _Elem char_type; typedef _Traits traits_type; typedef typename _Traits::int_type int_type; typedef typename _Traits::pos_type pos_type; typedef typename _Traits::off_type off_type; explicit __CLR_OR_THIS_CALL basic_ios(_Mysb *_Strbuf) { // construct from stream buffer pointer init(_Strbuf); } virtual __CLR_OR_THIS_CALL ~basic_ios() _NOEXCEPT { // destroy the object } void __CLR_OR_THIS_CALL clear(iostate _State = goodbit, bool _Reraise = false) { // set state, possibly reraise exception ios_base::clear((iostate)(_Mystrbuf == 0 ? (int)_State | (int)badbit : (int)_State), _Reraise); } void __CLR_OR_THIS_CALL clear(io_state _State) { // set state to _State clear((iostate)_State); } //此处省去之后basic_ios的其他成员函数 }
ignore()函数
功能:ignore函数是输入流的成员函数,可用来读取并抛弃残留在流缓冲区中的包括‘\n’在内的字符。
定义在
<istream>头文件中,用法如
cin.ignore(numeric_limits<int>::max, ‘\n’),这里用于读取近乎无限个字符,或者遇到了‘\n’,以下是摘取的ignore函数的源码:
_Myt& __CLR_OR_THIS_CALL ignore(streamsize _Count = 1,int_type _Metadelim = _Traits::eof()) { // ignore up to _Count characters, discarding delimiter ios_base::iostate _State = ios_base::goodbit; _Chcount = 0; const sentry _Ok(*this, true); if (_Ok && 0 < _Count) { // state okay, use facet to extract _TRY_IO_BEGIN for (; ; ) { // get a metacharacter if more room in buffer int_type _Meta; if (_Count != INT_MAX && --_Count < 0) break; //buffer full, quit else if (_Traits::eq_int_type(_Traits::eof(), _Meta = _Myios::rdbuf()->sbumpc())) { // end of file, quit _State |= ios_base::eofbit; break; } else { // got a character, count it ++_Chcount; if (_Meta == _Metadelim) break; // got a delimiter, quit } } _CATCH_IO_END } _Myios::setstate(_State); return (*this); }
其中,
_Count指被拋弃字符的最大数目,默认为1;
_Metadelim指遇到此字符后ignore函数停止运行(注意:此字符将被拋弃),默认为EOF字符(即遇到文件尾)。
system()系列函数
1.system(“pause>nul”)
用于在输出时,等按下任意键后才会返回,且不显示”请按任意键继续”;
2.system(“pause”)
用于在输出时,等按下任意键后才会返回;
3.system(“cls”)
可以实现清屏操作
相关文章推荐
- 用popen函数操作其它程序的输入和输出
- 第九周任务四(建立一个二维数组类Douary,使该类中有以下数据成员、成员函数及友员函数,完成矩阵的输入、输出、加、减、相等判断等操作。)
- Android For JNI(二)——C语言中的数据类型,输出,输入函数以及操作内存地址,内存修改器
- 第九周实验报告(四)建立一个二维数组类Douary,使该类中有以下数据成员、成员函数及友员函数,完成矩阵的输入、输出、加、减、相等判断等操作
- Android For JNI(二)——C语言中的数据类型,输出,输入函数以及操作内存地址,内存修改器
- 用popen函数操作其它程序的输入和输出
- linux中的管理输入输出以及vim的相关操作
- 用popen函数操作其它程序的输入和输出
- Linux 路由 学习笔记 之十一 输入、输出路由查找相关的接口函数
- 用popen函数操作其它程序的输入和输出
- 8086汇编:输入输出和数组操作的一些函数
- 第九周任务四之 建立一个二维数组类Douary,使该类中有以下数据成员、成员函数及友员函数,完成矩阵的输入、输出、加、减、相等判断等操作。
- 用popen函数操作其它程序的输入和输出
- python基础教程之popen函数操作其它程序的输入和输出示例
- 输入m个学生,每个学生有4门课,在主调函数中输入学生的相关信息,编写三个函数: (1)求第一门课的平均分; (2)找出有两门课以上不及格的学生,并输出他们的学号和全部成绩,要求用指针函数实现:fl
- JAVA-输入输出流相关的一些操作及用法详解
- (十七)文件操作——其余相关函数的介绍、以及递归输出目录中的文件列表
- python基础教程之popen函数操作其它程序的输入和输出示例
- STL中流相关的输入输出符和get函数彻底总结:cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
- 第九周实验报告任务4 建立一个二维数组类Douary,使该类中有以下数据成员、成员函数及友员函数,完成矩阵的输入、输出、加、减、相等判断等操作。