]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/stdstream.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxStdInputStream, wxStdInputStreamBuffer,
4 // wxStdOutputStream, wxStdOutputStreamBuffer
5 // Author: Jonathan Liu <net147@gmail.com>
7 // Copyright: (c) 2009 Jonathan Liu
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 @class wxStdInputStreamBuffer
14 wxStdInputStreamBuffer is a std::streambuf derived stream buffer which
15 reads from a wxInputStream.
19 wxFFileInputStream file("input.txt.gz");
20 wxZlibInputStream gzipInput(file, wxZLIB_GZIP);
21 wxStdInputStreamBuffer gzipStreamBuffer(gzipInput);
23 // redirect std::cin to read from compressed file
24 std::streambuf* streamBufferOld = std::cin.rdbuf(&gzipStreamBuffer);
28 std::cout << "Enter an integer: " << std::flush;
30 std::cout << std::endl;
31 std::cout << "You entered the integer " << number << "." << std::endl;
34 std::cin.rdbuf(streamBufferOld);
40 @see wxInputStream, wxStdInputStream
42 class wxStdInputStreamBuffer
: public std::streambuf
46 Creates a std::steambuf derived stream buffer which reads from a
52 wxStdInputStreamBuffer(wxInputStream
& stream
);
57 virtual ~wxStdInputStreamBuffer() { }
61 @class wxStdInputStream
63 wxStdInputStream is a std::istream derived stream which reads from
68 wxFFileInputStream file("words.txt");
69 wxStdInputStream in(file);
70 std::vector<std::string> words;
72 // read words from words.txt
73 std::copy(std::istream_iterator<std::string>(in),
74 std::istream_iterator<std::string>(),
75 std::back_inserter(words));
77 // sort and remove duplicates
78 std::sort(words.begin(), words.end());
79 words.resize(std::unique(words.begin(), words.end()) - words.begin());
82 std::copy(words.begin(), words.end(),
83 std::ostream_iterator<std::string>(std::cout, "\n"));
89 @see wxInputStream, wxStdInputStreamBuffer
91 class wxStdInputStream
: public std::istream
95 Creates a std::istream derived stream which reads from a
101 wxStdInputStream(wxInputStream
& stream
);
106 virtual ~wxStdInputStream() { }
110 @class wxStdOutputStreamBuffer
112 wxStdOutputStreamBuffer is a std::streambuf derived stream buffer which
113 writes to a wxOutputStream.
117 wxFFileOutputStream file("cout.txt.gz");
118 wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
119 wxStdOutputStreamBuffer gzipStreamBuffer(gzipOutput);
121 // redirect std::cout to cout.txt.gz using GZIP compression
122 std::streambuf* streamBufferOld = std::cout.rdbuf(&gzipStreamBuffer);
124 // write to std::cout
125 std::cout << "Hello world!" << std::endl;
128 std::cout.rdbuf(streamBufferOld);
134 @see wxOutputStream, wxStdOutputStream
136 class wxStdOutputStreamBuffer
: public std::streambuf
140 Creates a std::steambuf derived stream buffer which writes to a
146 wxStdOutputStreamBuffer(wxOutputStream
& stream
);
151 virtual ~wxStdOutputStreamBuffer() { }
155 @class wxStdOutputStream
157 wxStdOutputStream is a std::ostream derived stream which writes to a
162 wxFFileOutputStream file("out.txt.gz");
163 wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
164 wxStdOutputStream out(gzipOutput);
166 out << "Hello world!" << std::endl;
172 @see wxOutputStream, wxStdOutputStreamBuffer
174 class wxStdOutputStream
: public std::ostream
178 Creates a std::ostream derived stream which writes to a
184 wxStdOutputStream(wxOutputStream
& stream
);
189 virtual ~wxStdOutputStream() { }