<iostream>头文件源码
时间: 2023-06-12 10:07:09 浏览: 114
以下是<iostream>头文件的源码:
```cpp
#ifndef _IOSTREAM_H
#define _IOSTREAM_H
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
extern std::ios_base::Init __ioinit;
class ios_base : public std::ios_base {
public:
class failure : public std::exception {
public:
failure(const std::string&);
virtual ~failure() throw();
virtual const char* what() const throw();
};
static bool sync_with_stdio(bool sync = true);
static bool sync_with_stdio(bool sync = true, int& old_state);
static int xalloc();
static void sync_with_stdio();
};
template <typename _CharT, typename _Traits = std::char_traits<_CharT> >
class basic_ios : public std::basic_ios<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
protected:
basic_streambuf<char_type, traits_type>* rdbuf() const;
void rdbuf(basic_streambuf<char_type, traits_type>* sb);
public:
basic_ios();
virtual ~basic_ios();
void clear(iostate state = goodbit);
iostate exceptions() const;
void exceptions(iostate except);
bool good() const;
bool eof() const;
bool fail() const;
bool bad() const;
iostate rdstate() const;
void setstate(iostate state);
void tie(basic_ostream<char_type, traits_type>* os);
basic_ostream<char_type, traits_type>* tie() const;
char_type fill() const;
char_type fill(char_type ch);
int precision(int prec);
int precision() const;
int width(int wide);
int width() const;
static const basic_ios& __STL_CALL endl(basic_ios& __strm);
static const basic_ios& __STL_CALL ends(basic_ios& __strm);
static const basic_ios& __STL_CALL flush(basic_ios& __strm);
};
template <typename _CharT, typename _Traits = std::char_traits<_CharT> >
class basic_iostream : public std::basic_iostream<_CharT, _Traits> {
public:
typedef _CharT char_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
typedef _Traits traits_type;
protected:
basic_streambuf<char_type, traits_type>* rdbuf() const;
void rdbuf(basic_streambuf<char_type, traits_type>* sb);
public:
basic_iostream();
~basic_iostream();
basic_istream<char_type, traits_type>& operator>>(basic_iostream& (*__pf)(basic_istream<char_type, traits_type>&)) {
__pf(*this);
return (*this);
}
basic_ostream<char_type, traits_type>& operator<<(basic_ostream<char_type, traits_type>& (*__pf)(basic_ostream<char_type, traits_type>&)) {
__pf(*this);
return (*this);
}
};
typedef basic_ios<char> ios;
typedef basic_iostream<char> iostream;
typedef basic_istream<char> istream;
typedef basic_ostream<char> ostream;
typedef basic_ios<wchar_t> wios;
typedef basic_iostream<wchar_t> wiostream;
typedef basic_istream<wchar_t> wistream;
typedef basic_ostream<wchar_t> wostream;
#endif /* _IOSTREAM_H */
```
这个头文件定义了输入输出的基本类和函数,使得我们可以在程序中使用输入输出操作。
阅读全文