streambuf::overflow && streambuf::xsputn

Why my source doesn't work?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>


#include <streambuf>
#include <locale>
#include <cstdio>

class outbuf : public std::streambuf
{
  protected:
    /* central output function
     * - print characters in uppercase mode
     */
    virtual int_type overflow (int_type c) {
        if (c != EOF) {
            // convert lowercase to uppercase
            c = std::toupper(c,getloc());

            // and write the character to the standard output
            if (putchar(c) == EOF) {
                return EOF;
            }
        }
        return c;
    }

	virtual std::streamsize xsputn (const char_type * s, std::streamsize n)
	{
		fwrite( s, 20, 1, stdin );
		return n;
	}
};


int main()
{
    outbuf ob;                // create special output buffer
    std::ostream out(&ob);    // initialize output stream with that output buffer

    out << "31 hexadecimal: " << std::hex << 31 << std::endl;
	system( "pause" );
}


Another question:

what's the difference between overflow function and xsputn function?

and

in this line:
virtual std::streamsize xsputn (const char_type * s, std::streamsize n)

what is char_type?
Last edited on
up!

Please
Topic archived. No new replies allowed.