<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sstream on Cheat Sheet</title><link>/tags/sstream/</link><description>Recent content in Sstream on Cheat Sheet</description><generator>Hugo</generator><language>en</language><atom:link href="/tags/sstream/index.xml" rel="self" type="application/rss+xml"/><item><title>The IO Library</title><link>/programming/cpp/primer/io-library/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>/programming/cpp/primer/io-library/</guid><description>&lt;h1 id="the-io-library"&gt;The IO Library&lt;a class="anchor" href="#the-io-library"&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Summary based on &lt;em&gt;C++ Primer, 5th ed.&lt;/em&gt; Chapter 8 (The IO Library).&lt;/p&gt;
&lt;h2 id="1-io-library-headers-and-inheritance-hierarchy"&gt;1. IO Library Headers and Inheritance Hierarchy&lt;a class="anchor" href="#1-io-library-headers-and-inheritance-hierarchy"&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The C++ IO library is organized into three main headers handling console, file, and in-memory string streams, sharing a unified interface through &lt;strong&gt;inheritance&lt;/strong&gt;.&lt;/p&gt;
&lt;table&gt;
 &lt;thead&gt;
 &lt;tr&gt;
 &lt;th style="text-align: left"&gt;Header&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Core Types / Objects&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Base Class (&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;, &lt;code&gt;getline&lt;/code&gt; Inherited)&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Type-Specific Member Functions&lt;/th&gt;
 &lt;th style="text-align: left"&gt;Role&lt;/th&gt;
 &lt;/tr&gt;
 &lt;/thead&gt;
 &lt;tbody&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;&lt;code&gt;&amp;lt;iostream&amp;gt;&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;Types:&lt;/strong&gt; &lt;code&gt;istream&lt;/code&gt;, &lt;code&gt;ostream&lt;/code&gt;, &lt;code&gt;iostream&lt;/code&gt;&lt;br&gt;&lt;strong&gt;Global Objects:&lt;/strong&gt; &lt;code&gt;cin&lt;/code&gt;, &lt;code&gt;cout&lt;/code&gt;, &lt;code&gt;cerr&lt;/code&gt; (unbuffered), &lt;code&gt;clog&lt;/code&gt; (buffered)&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Root stream base classes&lt;/td&gt;
 &lt;td style="text-align: left"&gt;-&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Console (standard I/O) streams&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;&lt;code&gt;&amp;lt;fstream&amp;gt;&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;ifstream&lt;/code&gt;, &lt;code&gt;ofstream&lt;/code&gt;, &lt;code&gt;fstream&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Inherits from &lt;code&gt;istream&lt;/code&gt;, &lt;code&gt;ostream&lt;/code&gt;, &lt;code&gt;iostream&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;.open()&lt;/code&gt;, &lt;code&gt;.close()&lt;/code&gt;, &lt;code&gt;.is_open()&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;File I/O streams&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td style="text-align: left"&gt;&lt;strong&gt;&lt;code&gt;&amp;lt;sstream&amp;gt;&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;istringstream&lt;/code&gt;, &lt;code&gt;ostringstream&lt;/code&gt;, &lt;code&gt;stringstream&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;Inherits from &lt;code&gt;istream&lt;/code&gt;, &lt;code&gt;ostream&lt;/code&gt;, &lt;code&gt;iostream&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;&lt;code&gt;.str()&lt;/code&gt;, &lt;code&gt;.str(S)&lt;/code&gt;&lt;/td&gt;
 &lt;td style="text-align: left"&gt;In-memory &lt;code&gt;std::string&lt;/code&gt; streams&lt;/td&gt;
 &lt;/tr&gt;
 &lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote class='book-hint '&gt;
&lt;p&gt;&lt;strong&gt;Benefit of Polymorphism:&lt;/strong&gt; Because &lt;code&gt;ifstream&lt;/code&gt; and &lt;code&gt;istringstream&lt;/code&gt; both inherit from &lt;code&gt;std::istream&lt;/code&gt;, any function taking a &lt;code&gt;std::istream&amp;amp;&lt;/code&gt; reference (e.g., &lt;code&gt;read(std::istream&amp;amp;, Sales_data&amp;amp;)&lt;/code&gt;) works seamlessly with &lt;code&gt;std::cin&lt;/code&gt;, file streams (&lt;code&gt;ifstream&lt;/code&gt;), and string streams (&lt;code&gt;istringstream&lt;/code&gt;) without modification.&lt;/p&gt;</description></item></channel></rss>