{"id":1818,"date":"2025-01-25T17:26:37","date_gmt":"2025-01-25T17:26:37","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/?page_id=1818"},"modified":"2025-01-25T18:09:54","modified_gmt":"2025-01-25T18:09:54","slug":"unformatted-i-o","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/topics\/c-details\/i-o-streams\/unformatted-i-o\/","title":{"rendered":"Unformatted I\/O"},"content":{"rendered":"\n<h2 class=\"wp-block-heading has-000000-color has-text-color\"><span class=\"ez-toc-section\" id=\"Unformatted_IO\"><\/span>Unformatted I\/O<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h4 class=\"wp-block-heading has-000000-color has-text-color\"><span class=\"ez-toc-section\" id=\"ostream_writeconst_char_src_int_n\"><\/span><strong>ostream &amp;write(const char *src, int n)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"has-000000-color has-text-color\"><strong>write<\/strong> outputs the specified number of chars to a stream, from an array in memory:<\/p>\n\n\n\n<pre class=\"wp-block-code has-000000-color has-text-color\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>ostream &amp;write(const char *src, int n);<\/strong><\/code><\/pre>\n\n\n\n<p class=\"has-000000-color has-text-color\">It inserts <strong>n<\/strong> characters from the array <strong>src<\/strong> into the stream.<\/p>\n\n\n\n<h4 class=\"wp-block-heading has-000000-color has-text-color\"><span class=\"ez-toc-section\" id=\"istream_readchar_dst_int_n\"><\/span><strong>istream &amp;read(char *dst, int n)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"has-000000-color has-text-color\"><strong>read<\/strong> inputs the specified number of characters from a stream, into an array in memory:<\/p>\n\n\n\n<pre class=\"wp-block-code has-000000-color has-text-color\" style=\"padding-top:0px;padding-bottom:0px\"><code><strong>istream &amp;read(char *dst, int n);<\/strong><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading has-000000-color has-text-color\"><span class=\"ez-toc-section\" id=\"int_gcount\"><\/span><strong>int gcount()<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"has-000000-color has-text-color\"><strong>gcount<\/strong> returns the number of characters read by the last unformatted input operation (<strong>get<\/strong>, <strong>getline<\/strong>, and <strong>read<\/strong>):<\/p>\n\n\n\n<pre class=\"wp-block-code has-000000-color has-text-color\"><code><strong>int gcount();<\/strong><\/code><\/pre>\n\n\n\n<p class=\"has-000000-color has-text-color\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-000000-color has-text-color\"><code>char buffer&#91;80];\n<strong>cin.read(buffer, sizeof(buffer));<\/strong>\n<strong>cout &lt;&lt; \"read \" &lt;&lt; cin.gcount() \n     &lt;&lt; \" characters\" &lt;&lt; endl;<\/strong><\/code><\/pre>\n\n\n\n<div style=\"height:49px\" 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\/stream-manipulators\/\">Next: Stream Manipulators<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Unformatted I\/O ostream &amp;write(const char *src, int n) write outputs the specified number of chars to a stream, from an array in memory: It inserts n characters from the array src into the stream. istream &amp;read(char *dst, int n) read inputs the specified number of characters from a stream, into an array in memory: int [&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-1818","page","type-page","status-publish","hentry"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/1818","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=1818"}],"version-history":[{"count":2,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/1818\/revisions"}],"predecessor-version":[{"id":1841,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalCPlusPlusProgramming\/index.php\/wp-json\/wp\/v2\/pages\/1818\/revisions\/1841"}],"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=1818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}