{"id":4219,"date":"2022-01-31T08:08:53","date_gmt":"2022-01-31T08:08:53","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4219"},"modified":"2022-01-31T08:08:54","modified_gmt":"2022-01-31T08:08:54","slug":"13b-wxwidgets-stream-classes","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/31\/13b-wxwidgets-stream-classes\/","title":{"rendered":"13b. wxWidgets &#8211; Stream Classes"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>In this section we look at stream classes. wxWidgets has a good number of stream classes for raw input, output, file handling, text handling and archive formats. Stream classes are meant to be used with each other for the particular task at hand.<\/p>\n\n\n\n<p>In the same code below, we create a text file, then we create a zip file and add the text file to the zip file.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">streams.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n#include &lt;wx\/wfstream.h&gt;\n#include &lt;wx\/txtstrm.h&gt;\n#include &lt;wx\/zipstrm.h&gt;\n\nint main(int argc, char **argv) {\n\n\twxFFileOutputStream * fout = new wxFFileOutputStream(wxT(&quot;data.txt&quot;), wxT(&quot;w&quot;));\n\tif (!fout-&gt;IsOk()) {\n\t\twxPuts(wxT(&quot;Error - could not create data.txt&quot;));\n\t\treturn -1;\t\t\n\t}\n\n\twxTextOutputStream *tout = new wxTextOutputStream(*fout);\n\twxString row = wxT(&quot;&quot;);\n\twxString data = wxT(&quot;&quot;);\n\tfor(int i =0; i &lt; 100; i++) {\n\t  row = &quot;this is line number &quot;;\n\t  row.Append(wxString::Format(wxT(&quot;%d&quot;), i));\n\t  tout-&gt;WriteString(row);\n\t  tout-&gt;PutChar(wxT(&#039;\\n&#039;));\n\t  data.Append(row).Append(wxT(&#039;\\n&#039;));\n\t}\n\tfout-&gt;Close();\n\n\tfout = new wxFFileOutputStream(wxT(&quot;data.txt.zip&quot;));\n\twxZipOutputStream *zout = new wxZipOutputStream(*fout);\n\tif (!zout-&gt;IsOk()) {\n\t\twxPuts(wxT(&quot;Error creating data.txt.zip&quot;));\n\t\treturn -1;\n\t}\n\ttout = new wxTextOutputStream(*zout);\n\tzout-&gt;PutNextEntry(wxT(&quot;data.txt&quot;));\n\ttout-&gt;WriteString(data);\n\tzout-&gt;Close();\n\n\n\twxPuts(wxT(&quot;Done&quot;));\n}\n\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"549\" height=\"122\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-31-13-37-55.png\" alt=\"\" class=\"wp-image-4222\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-31-13-37-55.png 549w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-31-13-37-55-300x67.png 300w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW In this section we look at stream classes. wxWidgets has a good number of stream classes for raw input, output, file handling, text handling <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/31\/13b-wxwidgets-stream-classes\/\" title=\"13b. wxWidgets &#8211; Stream Classes\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-4219","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4219"}],"version-history":[{"count":3,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4219\/revisions"}],"predecessor-version":[{"id":4223,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4219\/revisions\/4223"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}