{"id":1811,"date":"2025-01-25T16:04:05","date_gmt":"2025-01-25T16:04:05","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/?page_id=1811"},"modified":"2025-01-26T17:54:14","modified_gmt":"2025-01-26T17:54:14","slug":"what-are-streams","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/topics\/c-details\/i-o-streams\/what-are-streams\/","title":{"rendered":"What are Streams?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_are_Streams\"><\/span>What are Streams?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>A Stream is simply a sequence of bytes.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>Streams of bytes flow from one place to another:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>From a device to memory (input operation)<\/li>\n\n\n\n<li>From memory to a device (output operation)<\/li>\n\n\n\n<li>From memory to memory<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>The bytes may represent:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Text, Graphics, Audio, Video, Raw data, whatever\u2026<\/li>\n<\/ul>\n\n\n\n<p><em>The application must associate meaning with the bytes in the stream.<\/em><\/p>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:33px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>C++ supplies classes that provide both:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>low-level (unformatted) I\/O capabilities<\/em><\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p><em><\/em><em>and:<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>high-level (formatted) I\/O capabilities<\/em><\/li>\n<\/ul>\n<\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Stream_Library_Header_Files\"><\/span>Stream Library Header Files<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-tableberg-wrapper is-style-stripes wp-block-tableberg-table\" >\n\t\t\t<div class=\"tableberg-table-wrapper\" style=\"\">\n\t\t\t\t<table class = \"has-inner-border\" style=\"--tableberg-even-bg: #f0f0f0; --tableberg-odd-bg: #ffffff; --tableberg-header-bg: #ffffff; --tableberg-footer-bg: #ffffff; border-spacing: 0 0; --tableberg-inner-border-top: none; --tableberg-inner-border-right: 1px solid #000000; --tableberg-inner-border-bottom: 1px solid #000000; --tableberg-inner-border-left: none; --tableberg-inner-border-top-first: 1px solid #000000; --tableberg-inner-border-left-first: 1px solid #000000; \" data-tableberg-header=\"\" data-tableberg-footer=\"\"  ><colgroup><col style=\"width: 15%; min-width: 15%; \"\/><col style=\"\"\/><\/colgroup><tbody><tr class=\"tableberg-odd-row\" style=\"\">\n<td data-tableberg-row=\"0\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>#include &lt;iostream&gt;<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"0\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>Contains basic information required for all stream I\/O operations.&nbsp; It declares the cin, cout, cerr, and clog objects.&nbsp; It provides both formatted and unformatted capabilities.<\/p>\n<\/div><\/td>\n<\/tr><tr class=\"tableberg-even-row\" style=\"\">\n<td data-tableberg-row=\"1\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>#include &lt;iomanip&gt;<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"1\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>Contains information for performing formatted I\/O with <em>parameterized stream manipulators<\/em>.<\/p>\n<\/div><\/td>\n<\/tr><tr class=\"tableberg-odd-row\" style=\"\">\n<td data-tableberg-row=\"2\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>#include &lt;fstream&gt;<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"2\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><em>Contains information for user-controlled file processing operations.<\/em><\/p>\n<\/div><\/td>\n<\/tr><tr class=\"tableberg-even-row\" style=\"\">\n<td data-tableberg-row=\"3\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>#include &lt;strstream&gt;<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"3\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>Contains information for performing <em>in-memory formatting<\/em>.&nbsp; (Resembles file I\/O, but to and from memory rather than files.)<\/p>\n<\/div><\/td>\n<\/tr><tr class=\"tableberg-odd-row\" style=\"\">\n<td data-tableberg-row=\"4\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>#include &lt;stdiostream&gt;<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"4\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>Allows programs to mix the C and C++ I\/O styles.<\/p>\n<\/div><\/td>\n<\/tr><\/tbody><\/table>\n\t\t\t<\/div>\n\t\t<\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Stream_IO_Classes_and_Objects\"><\/span>Stream I\/O Classes and Objects<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Among other things, <strong>basic_iostream<\/strong> contains the classes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>basic_istream<\/strong> &#8212; supports stream input operations<\/li>\n\n\n\n<li><strong>basic_ostream<\/strong> &#8212; supports stream output operations<\/li>\n\n\n\n<li><strong>basic_iostream<\/strong> &#8212; supports both input and output<\/li>\n<\/ul>\n\n\n\n<p>These classes are derived from the base class <strong>basic_ios<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"281\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-9-1024x281.png\" alt=\"\" class=\"wp-image-1258\" srcset=\"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-9-1024x281.png 1024w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-9-300x82.png 300w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-9-768x210.png 768w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-9-1536x421.png 1536w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-9.png 1744w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The class <strong>basic_ios<\/strong> provides capabilities which all streams can inherit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"cin_cout_cerr_and_clog\"><\/span><strong><code>cin<\/code><\/strong>, <strong><code>cout<\/code><\/strong>, <strong><code>cerr<\/code><\/strong>, and <strong><code>clog<\/code><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><strong>istream<\/strong>, <strong>ostream<\/strong> and <strong>iostream<\/strong> are <strong>typedef<\/strong>s which provide specializations of <strong>basic_istream<\/strong>, <strong>basic_ostream<\/strong> and <strong>basic_iostream<\/strong> respectively.&nbsp;<br>They provide support for character input, character output and combined character input and output.<\/p>\n\n\n<div class=\"wp-block-tableberg-wrapper wp-block-tableberg-table\" >\n\t\t\t<div class=\"tableberg-table-wrapper\" style=\"\">\n\t\t\t\t<table class = \"has-inner-border\" style=\"--tableberg-even-bg: #f0f0f0; --tableberg-odd-bg: #ffffff; border-spacing: 0 0; --tableberg-inner-border-top: none; --tableberg-inner-border-right: 1px solid #000000; --tableberg-inner-border-bottom: 1px solid #000000; --tableberg-inner-border-left: none; --tableberg-inner-border-top-first: 1px solid #000000; --tableberg-inner-border-left-first: 1px solid #000000; \" data-tableberg-header=\"\" data-tableberg-footer=\"\"  ><colgroup><col style=\"width: 34%; min-width: 34%; \"\/><col style=\"\"\/><\/colgroup><tbody><tr class=\"tableberg-odd-row\" style=\"\">\n<td data-tableberg-row=\"0\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>cin<\/strong> is an object of class <strong>istream<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"0\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>connected to the standard input device<\/p>\n<\/div><\/td>\n<\/tr><tr class=\"tableberg-even-row\" style=\"\">\n<td data-tableberg-row=\"1\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>cout<\/strong> is an object of class <strong>ostream<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"1\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>connected to the standard output device<\/p>\n<\/div><\/td>\n<\/tr><tr class=\"tableberg-odd-row\" style=\"\">\n<td data-tableberg-row=\"2\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>cerr<\/strong> is an object of class <strong>ostream<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"2\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>connected to the standard error device<\/p>\n\n\n\n<p>unbuffered (output appears immediately)<\/p>\n<\/div><\/td>\n<\/tr><tr class=\"tableberg-even-row\" style=\"\">\n<td data-tableberg-row=\"3\" data-tableberg-col=\"0\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p><strong>clog<\/strong> is an object of class <strong>ostream<\/strong><\/p>\n<\/div><\/td>\n\n<td data-tableberg-row=\"3\" data-tableberg-col=\"1\" style=\"\" class=\"wp-block-tableberg-cell tableberg-v-align-center\"><div class=\"tableberg-cell-inner\" style=\"display: block; justify-content: center; flex-wrap: wrap; \">\n<p>connected to the standard error device<\/p>\n\n\n\n<p>buffered<\/p>\n<\/div><\/td>\n<\/tr><\/tbody><\/table>\n\t\t\t<\/div>\n\t\t<\/div>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"C_File_Processing_Classes\"><\/span>C++ File Processing Classes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Also, C++ file processing uses classes <strong>basic_ifstream<\/strong> (for file input), <strong>basic_ofstream<\/strong> (for file output), and <strong>basic_fstream<\/strong> (for file input and output):<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"290\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-11-1024x290.png\" alt=\"\" class=\"wp-image-1263\" srcset=\"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-11-1024x290.png 1024w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-11-300x85.png 300w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-11-768x217.png 768w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-11-1536x435.png 1536w, https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/wp-content\/uploads\/2024\/08\/image-11-2048x579.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>There are many more classes than this in the stream I\/O class hierarchy, but we\u2019ll just talk about these for now.<\/p>\n\n\n\n<div style=\"height:46px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-font-size has-medium-font-size\"><a class=\"wp-block-button__link has-palette-color-8-color has-text-color has-link-color wp-element-button\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/topics\/c-details\/i-o-streams\/stream-output\/\">Next: Stream Output<\/a><\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What are Streams? A Stream is simply a sequence of bytes. Streams of bytes flow from one place to another: The bytes may represent: The application must associate meaning with the bytes in the stream. C++ supplies classes that provide both: and: Stream Library Header Files Stream I\/O Classes and Objects Among other things, basic_iostream [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":936,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1811","page","type-page","status-publish","hentry"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/1811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/comments?post=1811"}],"version-history":[{"count":2,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/1811\/revisions"}],"predecessor-version":[{"id":1899,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/1811\/revisions\/1899"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/936"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/media?parent=1811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}