source: CMT/v1r18p20041201/Visual/tcout.cxx @ 1

Last change on this file since 1 was 1, checked in by arnault, 19 years ago

Import all tags

File size: 803 bytes
Line 
1#include <stdio.h> 
2#include <stdlib.h> 
3#include <iostream> 
4#include <fstream> 
5 
6using namespace std; 
7 
8char buf[256]; 
9int index = 0; 
10 
11class mysb : public streambuf
12{ 
13        int overflow (int c) 
14        { 
15                buf[index] = c; 
16                buf[index + 1] = 0; 
17                index++; 
18                if ((index > 200) || (c == '\n')) 
19                { 
20                        printf ("> %s\n", buf); 
21                        index = 0; 
22                } 
23                return (1); 
24        } 
25        int underflow () 
26        { 
27                return (EOF); 
28        } 
29}; 
30 
31int main () 
32{ 
33        mysb s; 
34        streambuf* old; 
35 
36        ifstream f ("../mgr/requirements"); 
37        if (f) 
38        { 
39                cout << "opened" << endl; 
40                f.close (); 
41        } 
42 
43        cout << "aaa" << endl; 
44 
45        old = cout.rdbuf (&s); 
46        //cout = &s;
47 
48        cout << "bbb" << endl; 
49 
50        old = cout.rdbuf (old); 
51        //cout = old;
52 
53        cout << "ccc" << endl; 
54 
55        return (0); 
56} 
Note: See TracBrowser for help on using the repository browser.