]>
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>
6 // Copyright: (c) 2009 Jonathan Liu
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 @class wxStdInputStreamBuffer
13 wxStdInputStreamBuffer is a std::streambuf derived stream buffer which
14 reads from a wxInputStream.
18 wxFFileInputStream file("input.txt.gz");
19 wxZlibInputStream gzipInput(file, wxZLIB_GZIP);
20 wxStdInputStreamBuffer gzipStreamBuffer(gzipInput);
22 // redirect std::cin to read from compressed file
23 std::streambuf* streamBufferOld = std::cin.rdbuf(&gzipStreamBuffer);
27 std::cout << "Enter an integer: " << std::flush;
29 std::cout << std::endl;
30 std::cout << "You entered the integer " << number << "." << std::endl;
33 std::cin.rdbuf(streamBufferOld);
39 @see wxInputStream, wxStdInputStream
41 class wxStdInputStreamBuffer
: public std::streambuf
45 Creates a std::steambuf derived stream buffer which reads from a
51 wxStdInputStreamBuffer(wxInputStream
& stream
);
56 virtual ~wxStdInputStreamBuffer() { }
60 @class wxStdInputStream
62 wxStdInputStream is a std::istream derived stream which reads from
67 wxFFileInputStream file("words.txt");
68 wxStdInputStream in(file);
69 std::vector<std::string> words;
71 // read words from words.txt
72 std::copy(std::istream_iterator<std::string>(in),
73 std::istream_iterator<std::string>(),
74 std::back_inserter(words));
76 // sort and remove duplicates
77 std::sort(words.begin(), words.end());
78 words.resize(std::unique(words.begin(), words.end()) - words.begin());
81 std::copy(words.begin(), words.end(),
82 std::ostream_iterator<std::string>(std::cout, "\n"));
88 @see wxInputStream, wxStdInputStreamBuffer
90 class wxStdInputStream
: public std::istream
94 Creates a std::istream derived stream which reads from a
100 wxStdInputStream(wxInputStream
& stream
);
105 virtual ~wxStdInputStream() { }
109 @class wxStdOutputStreamBuffer
111 wxStdOutputStreamBuffer is a std::streambuf derived stream buffer which
112 writes to a wxOutputStream.
116 wxFFileOutputStream file("cout.txt.gz");
117 wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
118 wxStdOutputStreamBuffer gzipStreamBuffer(gzipOutput);
120 // redirect std::cout to cout.txt.gz using GZIP compression
121 std::streambuf* streamBufferOld = std::cout.rdbuf(&gzipStreamBuffer);
123 // write to std::cout
124 std::cout << "Hello world!" << std::endl;
127 std::cout.rdbuf(streamBufferOld);
133 @see wxOutputStream, wxStdOutputStream
135 class wxStdOutputStreamBuffer
: public std::streambuf
139 Creates a std::steambuf derived stream buffer which writes to a
145 wxStdOutputStreamBuffer(wxOutputStream
& stream
);
150 virtual ~wxStdOutputStreamBuffer() { }
154 @class wxStdOutputStream
156 wxStdOutputStream is a std::ostream derived stream which writes to a
161 wxFFileOutputStream file("out.txt.gz");
162 wxZlibOutputStream gzipOutput(file, -1, wxZLIB_GZIP);
163 wxStdOutputStream out(gzipOutput);
165 out << "Hello world!" << std::endl;
171 @see wxOutputStream, wxStdOutputStreamBuffer
173 class wxStdOutputStream
: public std::ostream
177 Creates a std::ostream derived stream which writes to a
183 wxStdOutputStream(wxOutputStream
& stream
);
188 virtual ~wxStdOutputStream() { }