引入头文件#include <iostream>的时候发生了什么?

这篇具有很好参考价值的文章主要介绍了引入头文件#include <iostream>的时候发生了什么?。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

<iostream>
namespace std {
    extern istream cin;
    extern ostream cout;
    extern ostream cerr;
    extern ostream clog;
    extern wistream wcin;
    extern wostream wcout;
    extern wostream wcerr;
    extern wostream wclog;
    };

cin是什么?

cin
extern istream cin;
The object controls extractions from the standard input as a byte stream. Once the object is constructed, the call cin.tie() returns &cout.

cout是什么?

cout
extern ostream cout;
The object controls insertions to the standard output as a byte stream.

/@@/ 帮助文档
ios_base::fmtflags
typedef T1 fmtflags;
static const fmtflags boolalpha, dec, fixed, hex, internal,
left, oct, right, scientific, showbase, showpoint,
showpos, skipws, unitbuf, uppercase, adjustfield,
basefield, floatfield;
The type is an enumerated type T1 that describes an object that can store format flags. The distinct flag values are:

boolalpha, to insert or extract objects of type bool as names (such as true and false) rather than as numeric values.
dec, to insert or extract integer values in decimal format.
fixed, to insert floating-point values in fixed-point format (with no exponent field).
hex, to insert or extract integer values in hexadecimal format.
internal, to pad to a field width as needed by inserting fill characters at a point internal to a generated numeric field.
left, to pad to a field width as needed by inserting fill characters at the end of a generated field (left justification).
oct, to insert or extract integer values in octal format.
right, to pad to a field width as needed by inserting fill characters at the beginning of a generated field (right justification).
scientific, to insert floating-point values in scientific format (with an exponent field).
showbase, to insert a prefix that reveals the base of a generated integer field.
showpoint, to insert a decimal point unconditionally in a generated floating-point field.
showpos, to insert a plus sign in a non-negative generated numeric field.
skipws, to skip leading white space before certain extractions.
unitbuf, to flush output after each insertion.
uppercase, to insert uppercase equivalents of lowercase letters in certain insertions.
In addition, several useful values are:

adjustfield, internal | left | right
basefield, dec | hex | oct
floatfield, fixed | scientific

format flags values
adjustfield internal left right
basefield dec hex oct
floatfield fixed scientific
/*
The class describes the storage and member functions common to both 
input and output streams that do not depend on the template parameters.
(The template class basic_ios describes what is common and is dependent on template parameters.)
*/
// 查考@@帮助文档,帮助理解ios_base类
class ios_base {
public:
    class failure;
    typedef T1 fmtflags;
    static const fmtflags boolalpha, dec, fixed, hex, internal,
        left, oct, right, scientific, showbase, showpoint,
        showpos, skipws, unitbuf, uppercase, adjustfield,
        basefield, floatfield;
    typedef T2 iostate;
    static const iostate badbit, eofbit, failbit, goodbit;
    typedef T3 openmode;
    static const openmode app, ate, binary, in, out, trunc;
    typedef T4 seekdir;
    static const seekdir beg, cur, end;
    typedef T5 event;
    static const event copyfmt_event, erase_event,
        copyfmt_event;
    class Init;
    ios_base& operator=(const ios_base& rhs);
    fmtflags flags() const;
    fmtflags flags(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl);
    fmtflags setf(fmtflags fmtfl, fmtflags mask);
    void unsetf(fmtflags mask);
    streamsize precision() const;
    streamsize precision(streamsize prec);
    streamsize width() const;
    stramsize width(streamsize wide);
    locale imbue(const locale& loc);
    locale getloc() const;
    static int xalloc();
    long& iword(int idx);
    void *& pword(int idx);
    typedef void *(event_callback(event ev, ios_base& ios, int idx);
    void register_callback(event_callback pfn, int idx);
    static bool sync_with_stdio(bool sync = true);
protected:
    ios_base();
    };

/*
The template class describes the storage and member functions common to 
both input streams (of template class basic_istream) and output streams 
(of template class basic_ostream) that depend on the template parameters. 
*/
template <class E, class T = char_traits<E> >
    class basic_ios : public ios_base {
public:
    typedef E char_type;
    typedef T::int_type int_type;
    typedef T::pos_type pos_type;
    typedef T::off_type off_type;
    explicit basic_ios(basic_streambuf<E, T>* sb);
    virtual ~basic_ios();
    operator void *() const;
    bool operator!() const;
    iostate rdstate() const;
    void clear(iostate state = goodbit);
    void setstate(iostate state);
    bool good() const;
    bool eof() const;
    bool fail() const;
    bool bad() const;
    iostate exceptions() const;
    iostate exceptions(iostate except);
    basic_ios& copyfmt(const basic_ios& rhs);
    E fill() const;
    E fill(E ch);
    basic_ostream<E, T> *tie() const;
    basic_ostream<E, T> *tie(basic_ostream<E, T> *str);
    basic_streambuf<E, T> *rdbuf() const;
    basic_streambuf<E, T> *rdbuf(basic_streambuf<E, T> *sb);
    basic_ios& copyfmt(const basic_ios& rhs);
    locale imbue(const locale& loc);
    E widen(char ch);
    char narrow(E ch, char dflt);
protected:
    basic_ios();
    void init(basic_streambuf<E, T>* sb);
    };

/*
The template class describes an object that controls extraction of elements and encoded objects from a stream buffer with elements of type E, whose character traits are determined by the class T.

*/

template <class E, class T = char_traits<E> >
    class basic_istream : virtual public basic_ios<E, T> {
public:
    class sentry;
    explicit basic_istream(basic_streambuf<E, T> *sb);
    virtual ~istream();
    bool ipfx(bool noskip = false);
    void isfx();
    basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
    basic_istream& operator>>(basic_ios<E, T>& (*pf)(basic_ios<E, T>&));
    basic_istream& operator>>(ios_base<E, T>& (*pf)(ios_base<E, T>&));
    basic_istream& operator>>(basic_streambuf<E, T> *sb);
    basic_istream& operator>>(bool& n);
    basic_istream& operator>>(short& n);
    basic_istream& operator>>(unsigned short& n);
    basic_istream& operator>>(int& n);
    basic_istream& operator>>(unsigned int& n);
    basic_istream& operator>>(long& n);
    basic_istream& operator>>(unsigned long& n);
    basic_istream& operator>>(void *& n);
    basic_istream& operator>>(float& n);
    basic_istream& operator>>(double& n);
    basic_istream& operator>>(long double& n);
    streamsize gcount() const;
    int_type get();
    basic_istream& get(E& c);
    basic_istream& get(E *s, streamsize n);
    basic_istream& get(E *s, streamsize n, E delim);
    basic_istream& get(basic_streambuf<E, T> *sb);
    basic_istream& get(baiic_streambuf<E, T> *sb, E delim);
    basic_istream& getline(E *s, streamsize n)E
    basic_istream& getline(E *s, streamsize n, E delim);
    basic_istream& ignore(streamsize n = 1,
        int_type delim = T::eof());
    int_type peek();
    basic_istream& read(E *s, streamsize n);
    streamsize readsome(E *s, streamsize n);
    basic_istream& putback(E c);
    basic_istream& unget();
    pos_type tellg();
    basic_istream& seekg(pos_type pos);
    basic_istream& seekg(off_type off, ios_base::seek_dir way);
    int sync();
    };
	
/*
The template class describes an object that controls extraction of elements and encoded objects from a stream buffer of class basic_filebuf<E, T>, with elements of type E, whose character traits are determined by the class T. The object stores an object of class basic_filebuf<E, T>.
*/
template <class E, class T = char_traits<E> >
    class basic_ifstream : public basic_istream<E, T> {
public:
    explicit basic_ifstream();
    explicit basic_ifstream(const char *s,
        ios_base::openmode mode = ios_base::in);
    basic_filebuf<E, T> *rdbuf() const;
    bool is_open() const;
    void open(const char *s,
        ios_base::openmode mode = ios_base::in);
    void close();
    };
	
/*
The template class describes an object that controls extraction of elements and encoded objects from a stream buffer of class basic_stringbuf<E, T, A>, with elements of type E, whose character traits are determined by the class T, and whose elements are allocated by an allocator of class A. The object stores an object of class basic_stringbuf<E, T, A>.
*/
template <class E,
    class T = char_traits<E>,
    class A = allocator<E> >
    class basic_istringstream : public basic_istream<E, T> {
public:
    explicit basic_istringstream(ios_base::openmode mode = ios_base::in);
    explicit basic_istringstream(const basic_string<E, T, A>& x,
        ios_base::openmode mode = ios_base::in);
    basic_stringbuf<E, T, A> *rdbuf() const;
    basic_string<E, T, A>& str();
    void str(const basic_string<E, T, A>& x);
    };


/*
The template class describes an object that controls insertion of elements and encoded objects into a stream buffer with elements of type E, whose character traits are determined by the class T.
*/
template <class E, class T = char_traits<E> >
    class basic_ostream : virtual public basic_ios<E, T>{
public:
    class sentry;
    explicit basic_ostream(basic_streambuf<E, T> *sb);
    virtual ~ostream();
    bool opfx();
    void osfx();
    basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
    basic_ostream& operator<<(basic_ios<E, T>& (*pf)(basic_ios<E, T>&));
    basic_ostream& operator<<(ios_base<E, T>& (*pf)(ios_base<E, T>&));
    basic_ostream& operator<<(basic_streambuf<E, T> *sb);
    basic_ostream& operator<<(const char *s);
    basic_ostream& operator<<(char c);
    basic_ostream& operator<<(bool n);
    basic_ostream& operator<<(short n);
    basic_ostream& operator<<(unsigned short n);
    basic_ostream& operator<<(int n);
    basic_ostream& operator<<(unsigned int n);
    basic_ostream& operator<<(long n);
    basic_ostream& operator<<(unsigned long n);
    basic_ostream& operator<<(float n);
    basic_ostream& operator<<(double n);
    basic_ostream& operator<<(long double n);
    basic_ostream& operator<<(void * n);
    basic_ostream& put(E c);
    basic_ostream& write(E *s, streamsize n);
    basic_ostream& flush();
    pos_type tellp();
    basic_ostream& seekp(pos_type pos);
    basic_ostream& seekp(off_type off, ios_base::seek_dir way);
    };
/*
The template class describes an object that controls insertion of elements and encoded objects into a stream buffer of class basic_stringbuf<E, T, A>, with elements of type E, whose character traits are determined by the class T, and whose elements are allocated by an allocator of class A. The object stores an object of class basic_stringbuf<E, T, A>.

*/
template <class E,
    class T = char_traits<E>,
    class A = allocator<E> >
    class basic_ostringstream : public basic_ostream<E, T> {
public:
    explicit basic_ostringstream(ios_base::openmode mode = ios_base::out);
    explicit basic_ostringstream(const basic_string<E, T, A>& x,
        ios_base::openmode mode = ios_base::out);
    basic_stringbuf<E, T, A> *rdbuf() const;
    basic_string<E, T, A>& str();
    void str(const basic_string<E, T, A>& x);
    };


/*
The template class describes an object that controls insertion of elements and encoded objects into a stream buffer of class basic_filebuf<E, T>, with elements of type E, whose character traits are determined by the class T. The object stores an object of class basic_filebuf<E, T>.
*/
template <class E, class T = char_traits<E> >
    class basic_ofstream : public basic_ostream<E, T> {
public:
    explicit basic_ofstream();
    explicit basic_ofstream(const char *s,
        ios_base::openmode mode = ios_base::out | ios_base::trunc);
    basic_filebuf<E, T> *rdbuf() const;
    bool is_open() const;
    void open(const char *s,
        ios_base::openmode mode = ios_base::out | ios_base::trunc);
    void close();
    };

/*
The template class describes an object that controls insertions, 
through its base object basic_ostream<E, T>, and extractions, 
through its base object basic_istream<E, T>. The two objects 
share a common virtual base object basic_ios<E, T>. 
They also manage a common stream buffer, with elements of type E,
 whose character traits are determined by the class T.
 The constructor initializes its base objects via basic_istream(sb) and basic_ostream(sb).
*/
template <class E, class T = char_traits<E> >
    class basic_iostream : public basic_istream<E, T>,
        public  basic_ostream<E, T> {
public:
    explicit basic_iostream(basic_streambuf<E, T> *sb);
    virtual ~basic_iostream();
    };

/*
The template class describes an object that controls insertion and
 extraction of elements and encoded objects using a stream
 buffer of class basic_stringbuf<E, T, A>, with elements of type E,
 whose character traits are determined by the class T, 
 and whose elements are allocated by an allocator of class A. 
 The object stores an object of class basic_stringbuf<E, T, A>.
*/
	template <class E,
    class T = char_traits<E>,
    class A = allocator<E> >
    class basic_stringstream : public basic_iostream<E, T> {
public:
    explicit basic_stringstream(ios_base::openmode mode = ios_base::in | ios_base::out);
    explicit basic_stringstream(const basic_string<E, T, A>& x,
        ios_base::openmode mode = ios_base::in | ios_base::out);
    basic_stringbuf<E, T, A> *rdbuf() const;
    basic_string<E, T, A>& str();
    void str(const basic_string<E, T, A>& x);
    };


	template <class E, class T = char_traits<E> >
    class basic_streambuf {
public:
    typedef E char_type;
    typedef T traits_type;
    typedef T::int_type int_type;
    typedef T::pos_type pos_type;
    typedef T::off_type off_type;
    virtual ~streambuf();
    locale pubimbue(const locale& loc);
    locale getloc() const;
    basic_streambuf *pubsetbuf(E *s, streamsize n);
    pos_type pubseekoff(off_type off, ios_base::seekdir way,
        ios_base::openmode which = ios_base::in | ios_base::out);
    pos_type pubseekpos(pos_type sp,
        ios_base::openmode which = ios_base::in | ios_base::out);
    int pubsync();
    streamsize in_avail();
    int_type snextc();
    int_type sbumpc();
    int_type sgetc();
    streamsize sgetn(E *s, streamsize n);
    int_type sputbackc(E c);
    int_type sungetc();
    int_type sputc(E c);
    streamsize sputn(const E *s, streamsize n);
protected:
    basic_streambuf();
    E *eback() const;
    E *gptr() const;
    E *egptr() const;
    void gbump(int n);
    void setg(E *gbeg, E *gnext, E *gend);
    E *pbase() const;
    E *pptr() const;
    E *epptr() const;
    void pbump(int n);
    void setp(E *pbeg, E *pend);
    virtual void imbue(const locale &loc);
    virtual basic_streambuf *setbuf(E *s, streamsize n);
    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
        ios_base::openmode which = ios_base::in | ios_base::out);
    virtual pos_type seekpos(pos_type sp,
        ios_base::openmode which = ios_base::in | ios_base::out);
    virtual int sync();
    virtual int showmanyc();
    virtual streamsize xsgetn(E *s, streamsize n);
    virtual int_type underflow();
    virtual int_type uflow();
    virtual int_type pbackfail(int_type c = T::eof());
    virtual streamsize xsputn(const E *s, streamsize n);
    virtual int_type overflow(int_type c = T::eof());
    };


template <class E, class T = char_traits<E> >
    class basic_filebuf : public basic_streambuf<E, T> {
public:
    basic_filebuf();
    bool is_open() const;
    basic_filebuf *open(const char *s, ios_base::openmode mode);
    basic_filebuf *close();
protected:
    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
        ios_base::openmode which = ios_base::in | ios_base::out);
    virtual pos_type seekpos(pos_type pos,
        ios_base::openmode which = ios_base::in | ios_base::out);
    virtual int_type underflow();
    virtual int_type pbackfail(int_type c = T::eof());
    virtual int_type overflow(int_type c = T::eof());
    virtual int sync();
    virtual basic_streambuf<E, T> *setbuf(E *s, streamsize n);
    };



template <class E,
    class T = char_traits<E>,
    class A = allocator<E> >
    class basic_stringbuf {
public:
    basic_stringbuf(ios_base::openmode mode =
        ios_base::in | ios_base::out);
    basic_stringbuf(basic_string<E, T, A>& x,
        ios_base::openmode mode = ios_base::in | ios_base::out);
    basic_string<E, T, A> str() const;
    void str(basic_string<E, T, A>& x);
protected:
    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
        ios_base::openmode mode = ios_base::in | ios_base::out);
    virtual pos_type seekpos(pos_type sp,
        ios_base::openmode mode = ios_base::in | ios_base::out);
    virtual int_type underflow();
    virtual int_type pbackfail(int_type c = T::eof());
    virtual int_type overflow(int_type c = T::eof());
    };

template<class E,
    class T = char_traits<E>,
    class A = allocator<T> >
    class basic_string {
public:
    typedef T traits_type;
    typedef A allocator_type;
    typedef T::char_type char_type;
    typedef A::size_type size_type;
    typedef A::difference_type difference_type;
    typedef A::pointer pointer;
    typedef A::const_pointer const_pointer;
    typedef A::reference reference;
    typedef A::const_reference const_reference;
    typedef A::value_type value_type;
    typedef T0 iterator;
    typedef T1 const_iterator;
    typedef reverse_iterator<iterator, value_type,
        reference, pointer, difference_type>
            reverse_iterator;
    typedef reverse_iterator<const_iterator, value_type,
        const_reference, const_pointer, difference_type>
            const_reverse_iterator;
    static const size_type npos = -1;
    explicit basic_string(const A& al = A());
    basic_string(const basic_string& rhs);
    basic_string(const basic_string& rhs, size_type pos, size_type n,
        const A& al = A());
    basic_string(const E *s, size_type n, const A& al = A());
    basic_string(const E *s, const A& al = A());
    basic_string(size_type n, E c, const A& al = A());
    basic_string(const_iterator first, const_iterator last,
        const A& al = A());
    basic_string& operator=(const basic_string& rhs);
    basic_string& operator=(const E *s);
    basic_string& operator=(E c);
    iterator begin();
    const_iterator begin() const;
    iterator end();
    const_iterator end() const;
    reverse_iterator rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator rend();
    const_reverse_iterator rend() const;
    const_reference at(size_type pos) const;
    reference at(size_type pos);
    const_reference operator[](size_type pos) const;
    reference operator[](size_type pos);
    const E *c_str() const;
    const E *data() const;
    size_type length() const;
    size_type size() const;
    size_type max_size() const;
    void resize(size_type n, E c = E());
    size_type capacity() const;
    void reserve(size_type n = 0);
    bool empty() const;
    basic_string& operator+=(const basic_string& rhs);
    basic_string& operator+=(const E *s);
    basic_string& operator+=(E c);
    basic_string& append(const basic_string& str);
    basic_string& append(const basic_string& str,
        size_type pos, size_type n);
    basic_string& append(const E *s, size_type n);
    basic_string& append(const E *s);
    basic_string& append(size_type n, E c);
    basic_string& append(const_iterator first, const_iterator last);
    basic_string& assign(const basic_string& str);
    basic_string& assign(const basic_string& str,
        size_type pos, size_type n);
    basic_string& assign(const E *s, size_type n);
    basic_string& assign(const E *s);
    basic_string& assign(size_type n, E c);
    basic_string& assign(const_iterator first, const_iterator last);
    basic_string& insert(size_type p0,
        const basic_string& str);
    basic_string& insert(size_type p0,
        const basic_string& str, size_type pos, size_type n);
    basic_string& insert(size_type p0,
        const E *s, size_type n);
    basic_string& insert(size_type p0, const E *s);
    basic_string& insert(size_type p0, size_type n, E c);
    iterator insert(iterator it, E c);
    void insert(iterator it, size_type n, E c);
    void insert(iterator it,
        const_iterator first, const_iterator last);
    basic_string& erase(size_type p0 = 0, size_type n = npos);
    iterator erase(iterator it);
    iterator erase(iterator first, iterator last);
    basic_string& replace(size_type p0, size_type n0,
        const basic_string& str);
    basic_string& replace(size_type p0, size_type n0,
        const basic_string& str, size_type pos, size_type n);
    basic_string& replace(size_type p0, size_type n0,
        const E *s, size_type n);
    basic_string& replace(size_type p0, size_type n0,
        const E *s);
    basic_string& replace(size_type p0, size_type n0,
        size_type n, E c);
    basic_string& replace(iterator first0, iterator last0,
        const basic_string& str);
    basic_string& replace(iterator first0, iterator last0,
        const E *s, size_type n);
    basic_string& replace(iterator first0, iterator last0,
        const E *s);
    basic_string& replace(iterator first0, iterator last0,
        size_type n, E c);
    basic_string& replace(iterator first0, iterator last0,
        const_iterator first, const_iterator last);
    size_type copy(E *s, size_type n, size_type pos = 0) const;
    void swap(basic_string& str);
    size_type find(const basic_string& str,
        size_type pos = 0) const;
    size_type find(const E *s, size_type pos, size_type n) const;
    size_type find(const E *s, size_type pos = 0) const;
    size_type find(E c, size_type pos = 0) const;
    size_type rfind(const basic_string& str,
        size_type pos = npos) const;
    size_type rfind(const E *s, size_type pos,
        size_type n = npos) const;
    size_type rfind(const E *s, size_type pos = npos) const;
    size_type rfind(E c, size_type pos = npos) const;
    size_type find_first_of(const basic_string& str,
        size_type pos = 0) const;
    size_type find_first_of(const E *s, size_type pos,
        size_type n) const;
    size_type find_first_of(const E *s, size_type pos = 0) const;
    size_type find_first_of(E c, size_type pos = 0) const;
    size_type find_last_of(const basic_string& str,
        size_type pos = npos) const;
    size_type find_last_of(const E *s, size_type pos,
        size_type n = npos) con/t;
    size_type find_last_of(const E *s, size_type pos = npos) const;
    size_type find_last_of(E c, size_type pos = npos) const;
    size_type find_first_not_of(const basic_string& str,
        size_type pos = 0) const;
    size_type find_first_not_of(const E *s, size_type pos,
        size_type n) const;
    size_type find_first_not_of(const E *s, size_type pos = 0) const;
    size_type find_first_not_of(E c, size_type pos = 0) const;
    size_type find_last_not_of(const basic_string& str,
        size_type pos = npos) const;
    size_type find_last_not_of(const E *s, size_type pos,
         size_type n) const;
    size_type find_last_not_of(const E *s,
        size_type pos = npos) const;
    size_type find_last_not_of(E c, size_type pos = npos) const;
    basic_string substr(size_type pos = 0, size_type n = npos) const;
    int compare(const basic_string& str) const;
    int compare(size_type p0, size_type n0,
        const basic_string& str);
    int compare(size_type p0, size_type n0,
        const basic_string& str, size_type pos, size_type n);
    int compare(const E *s) const;
    int compare(size_type p0, size_type n0,
        const E *s) const;
    int compare(size_type p0, size_type n0,
        const E *s, size_type pos) const;
    A get_allocator() const;
protected:
    A allocator;
    };


char_traits是什么?

至于上次这个问号,是从std::string的使用中发现的
typedef basic_string string;

template<class E,class traits = char_traits,
class Alloc = allocator >
class basic_string;

所以就对 char_traits 产生了问好?
以后有机会了再来研究 allocator

/// 21.1.3.1  char_traits specializations
template <class char_type, class _Int_type>
struct _Char_traits { // properties of a string or stream element
{
  typedef char              char_type;
  typedef int               int_type;
  typedef streampos         pos_type;
  typedef streamoff         off_type;
  typedef mbstate_t         state_type;

  static _GLIBCXX17_CONSTEXPR void
  assign(char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
  { __c1 = __c2; }

  static _GLIBCXX_CONSTEXPR bool
  eq(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
  { return __c1 == __c2; }

  static _GLIBCXX_CONSTEXPR bool
  lt(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT
  {
    // LWG 467.
    return (static_cast<unsigned char>(__c1)
    < static_cast<unsigned char>(__c2));
  }

  static /* _GLIBCXX17_CONSTEXPR */ int
  compare(const char_type* __s1, const char_type* __s2, size_t __n)
  {
    if (__n == 0)
      return 0;
    return __builtin_memcmp(__s1, __s2, __n);
  }

  static /* _GLIBCXX17_CONSTEXPR */ size_t
  length(const char_type* __s)
  { return __builtin_strlen(__s); }

  static /* _GLIBCXX17_CONSTEXPR */ const char_type*
  find(const char_type* __s, size_t __n, const char_type& __a)
  {
    if (__n == 0)
      return 0;
    return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n));
  }

  static char_type*
  move(char_type* __s1, const char_type* __s2, size_t __n)
  {
    if (__n == 0)
      return __s1;
    return static_cast<char_type*>(__builtin_memmove(__s1, __s2, __n));
  }

  static char_type*
  copy(char_type* __s1, const char_type* __s2, size_t __n)
  {
    if (__n == 0)
      return __s1;
    return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
  }

  static char_type*
  assign(char_type* __s, size_t __n, char_type __a)
  {
    if (__n == 0)
      return __s;
    return static_cast<char_type*>(__builtin_memset(__s, __a, __n));
  }

  static _GLIBCXX_CONSTEXPR char_type
  to_char_type(const int_type& __c) _GLIBCXX_NOEXCEPT
  { return static_cast<char_type>(__c); }

  // To keep both the byte 0xff and the eof symbol 0xffffffff
  // from ending up as 0xffffffff.
  static _GLIBCXX_CONSTEXPR int_type
  to_int_type(const char_type& __c) _GLIBCXX_NOEXCEPT
  { return static_cast<int_type>(static_cast<unsigned char>(__c)); }

  static _GLIBCXX_CONSTEXPR bool
  eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT
  { return __c1 == __c2; }

  static _GLIBCXX_CONSTEXPR int_type
  eof() _GLIBCXX_NOEXCEPT
  { return static_cast<int_type>(_GLIBCXX_STDIO_EOF); }

  static _GLIBCXX_CONSTEXPR int_type
  not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT
  { return (__c == eof()) ? 0 : __c; }
};

template <class _Ty>
class allocator {
public:
    static_assert(!is_const_v<_Ty>, "The C++ Standard forbids containers of const elements "
                                    "because allocator<const T> is ill-formed.");

    using _From_primary = allocator;

    using value_type = _Ty;

    typedef _Ty* pointer;
    typedef const _Ty* const_pointer;

    typedef _Ty& reference;
    typedef const _Ty& const_reference;

    using size_type       = size_t;
    using difference_type = ptrdiff_t;

    using propagate_on_container_move_assignment = true_type;
    using is_always_equal                        = true_type;

    template <class _Other>
    struct  rebind {
        using other = allocator<_Other>;
    };

    _NODISCARD _Ty* address(_Ty& _Val) const noexcept {
        return _STD addressof(_Val);
    }

    _NODISCARD const _Ty* address(const _Ty& _Val) const noexcept {
        return _STD addressof(_Val);
    }

    constexpr allocator() noexcept {}

    constexpr allocator(const allocator&) noexcept = default;
    template <class _Other>
    constexpr allocator(const allocator<_Other>&) noexcept {}

    void deallocate(_Ty* const _Ptr, const size_t _Count) {
        // no overflow check on the following multiply; we assume _Allocate did that check
        _Deallocate<_New_alignof<_Ty>>(_Ptr, sizeof(_Ty) * _Count);
    }

    _NODISCARD __declspec(allocator) _Ty* allocate(_CRT_GUARDOVERFLOW const size_t _Count) {
        return static_cast<_Ty*>(_Allocate<_New_alignof<_Ty>>(_Get_size_of_n<sizeof(_Ty)>(_Count)));
    }

    _NODISCARD __declspec(allocator) _Ty* allocate(
        _CRT_GUARDOVERFLOW const size_t _Count, const void*) {
        return allocate(_Count);
    }

    template <class _Objty, class... _Types>
    void construct(_Objty* const _Ptr, _Types&&... _Args) {
        ::new (const_cast<void*>(static_cast<const volatile void*>(_Ptr))) _Objty(_STD forward<_Types>(_Args)...);
    }

    template <class _Uty>
    void destroy(_Uty* const _Ptr) {
        _Ptr->~_Uty();
    }

    _NODISCARD size_t max_size() const noexcept {
        return static_cast<size_t>(-1) / sizeof(_Ty);
    }
};

除了使用继承将父类的特性和功能加到用户类中,还可以通过组合其他类到
用户类中扩展功能,但是其实还有一种方法来给一个用户类扩充功能,那就
是通过模板实现,如下,自己细品。

using string = basic_string<char,char_traits<char>,allocator<char> >
template<class _Elem,char _Traits = char_traits<_Elem>,class _Alloc = allocator<_Elem> >
class basic_string{
	// basic_string也即std::string中比较,相等,小于,复制,赋值,移动,长度,获取类型等操作来源于
	// 模板参数中的第二个char_traits<char>提供
}

会查资料的能力很重要

知道权威的官方资料文档如何查询
https://learn.microsoft.com/zh-cn/cpp/standard-library/char-traits-struct?view=msvc-170
引入头文件#include <iostream>的时候发生了什么?,C++挑马桶基本功,iostream头文件,C++流操作,C++基础文章来源地址https://www.toymoban.com/news/detail-576802.html

到了这里,关于引入头文件#include <iostream>的时候发生了什么?的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • C_01_include文件有什么妙用

    最近在看代码的过程中,发现一种新玩法,就是在一个*.c文件中,直接include另一个 *.c 文件,以往都是include一个 *.h文件。这个脑洞大开,神奇!随之而来的有两个问题: Q1. 这么写代码有什么效果? Q2. 想知道原作者为什么这么写代码 ? 先来看第一个问题,这么写代码有什么

    2024年01月25日
    浏览(29)
  • Dockerfile文件中只指定挂载点会发生什么?

    当你在 VOLUME 指令中只指定容器内的路径(挂载点)而不指定宿主机的目录时,Docker会为该挂载点自动生成一个匿名卷。这个匿名卷存储在宿主机的某个位置,但这个具体位置是由Docker自动管理的,用户通常不需要关心这个存储位置。 例如,Dockerfile中的一个 VOLUME 指令可能看

    2024年02月21日
    浏览(27)
  • 压缩算法的原理丨基因型vcf文件为什么压缩后发生了什么?

    最近碰到一个神奇的现象,一份大小为 16GB 的 xx.vcf.gz 文件,解压之后体积变为 600GB 的 vcf 文件,为什么一份文件经过压缩后体积缩小了这么多? 压缩 这个词联想到压缩机,就是把空气进行物理加压,减小占用的体积,这种方法利用的是单个分子之间的可变间隙,像挤海绵一

    2024年02月15日
    浏览(43)
  • 使用git时候提交时候发生冲突,你能解释冲突如何产生,你是如何解决的

    Git冲突情况举例: 简单来说就是本地修改的文件和目标远程库的同一个文件都有修改。这时无论是pull/push/merge时都会产生冲突。 1、不同分支下的merge 比如在不同分支下进行分支合并时,我们在本地修改了a文件并把a文件的修改push到了test分支下,接着我们切换到master分支下将

    2024年02月08日
    浏览(54)
  • 什么时候会触发FullGC?描述一下JVM加载class文件的原理机制?

    什么时候会触发 FullGC? 除直接调用 System.gc 外,触发 Full GC 执行的情况有如下四种。 1. 旧生代空间不足 旧生代空间只有 在新生代对象转入及创建为大对象、大数组时才会出现不足的现象,当执行 Full GC 后空间仍然不 足,则抛出如下错误: java.lang.OutOfMemoryError: Java heap spac

    2024年02月20日
    浏览(46)
  • PIco4发布使用UNITY开发的Vr应用,格式为apk,安装的时候发生解析错误

    参考链接 : adb install APK报错Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]_调用者不被允许测试的测试程序_小龙在山东的博客-CSDN博客 Pico Developer Answers 完成项目配置 - PICO 开发者平台 如何将apk、obb文件打包至pico设备中 - 掘金 Requires newer sdk version #30 (current version is #28) · Issue #633

    2024年02月04日
    浏览(60)
  • #include < > 和#include ” ”有什么区别?

    C语言头文件 C语言中头文件的扩展名为 .h的头文件,头文件中包含了函数的声明和宏定义,头文件可以被多个源文件引用。在C语言中有两种类型的头文件,一种是编译器自带的头文件,另一种就是程序员自己编写的头文件。 在C程序中如果要使用头文件,则必须使用头文件包

    2024年02月08日
    浏览(35)
  • Vue 报错: Already included file name ‘××ב differs from file name ‘××ב only in casing.但引入路径是正确的

    vue提示Already included file name \\\'.../components/TagsView.vue\\\' differs from file name 明明引入的文件名和地址都是正确的,但是还是报错误   解决方案一: 把文件名的后缀vue去掉   解决方案一: 把路径前面的点改成@

    2024年02月11日
    浏览(58)
  • 微信小程序通过npm引入tdesign包进行构建的时候报错

    问题 在通过npm 引入 tdesign时:https://tdesign.tencent.com/miniprogram/getting-started 通过微信小程序IDE进行npm构建的时候出现:无法构建,应该怎么办? 解决方法: 1 输入: 命令 2 重新点击工具-npm构建 这个时候,黑框出现一段Json,同时提示构建成功,即可开始使用tdesign了!

    2024年02月10日
    浏览(45)
  • C++ 中到底是应该include .h文件还是应该include .cpp文件

    在阅读一个较大的解决方案中,对于其他文件夹下的.h和.cpp文件,有时候#include“XXX.h”文件,有时候是#include“XXX.cpp”文件,而且二者还不能更换。下面就好好分析一下他们二者的区别。          如果 .h 文件和 .cpp 文件都已经添加在解决方案里,只要在 main 的头文件中

    2024年02月05日
    浏览(51)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包