A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FDevelopment%2Fcin</id>
		<title>C++ Tutorial/Development/cin - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B_Tutorial%2FDevelopment%2Fcin"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/cin&amp;action=history"/>
		<updated>2026-04-17T22:31:47Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/cin&amp;diff=2131&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/cin&amp;diff=2131&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:17Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/cin&amp;diff=2132&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B_Tutorial/Development/cin&amp;diff=2132&amp;oldid=prev"/>
				<updated>2010-05-25T10:28:57Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==avoids buffer overflow with cin.width==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;  &lt;br /&gt;
  #include &amp;lt;iomanip&amp;gt;             &lt;br /&gt;
  using namespace std;  &lt;br /&gt;
    &lt;br /&gt;
  int main(){  &lt;br /&gt;
     const int MAX = 20; &lt;br /&gt;
     char str[MAX];      &lt;br /&gt;
    &lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;\nEnter a string: &amp;quot;;  &lt;br /&gt;
     cin &amp;gt;&amp;gt; setw(MAX) &amp;gt;&amp;gt; str;&lt;br /&gt;
     cout &amp;lt;&amp;lt; &amp;quot;You entered: &amp;quot; &amp;lt;&amp;lt; str &amp;lt;&amp;lt; endl;  &lt;br /&gt;
     return 0;  &lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Character input with member function getline.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   const int SIZE = 80;&lt;br /&gt;
   char buffer[ SIZE ];&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a sentence:\n&amp;quot;;&lt;br /&gt;
   cin.getline( buffer, SIZE );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nThe sentence entered is:\n&amp;quot; &amp;lt;&amp;lt; buffer &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cin and atoi, atof functions==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
  char mybuffer [100];&lt;br /&gt;
  &lt;br /&gt;
  float price;&lt;br /&gt;
  &lt;br /&gt;
  int quantity;&lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Enter price: &amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  cin.getline (mybuffer,100);&lt;br /&gt;
  &lt;br /&gt;
  price = atof (mybuffer);&lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Enter quantity: &amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  cin.getline (mybuffer,100);&lt;br /&gt;
  &lt;br /&gt;
  quantity = atoi (mybuffer);&lt;br /&gt;
  &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Total price: &amp;quot; &amp;lt;&amp;lt; price*quantity;&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter price: 123&lt;br /&gt;
Enter quantity: 12&lt;br /&gt;
Total price: 1476&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cin Handles Different Data Types==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
   int myInt;&lt;br /&gt;
   long myLong;&lt;br /&gt;
   double myDouble;&lt;br /&gt;
   float myFloat;&lt;br /&gt;
   unsigned int myUnsigned;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;int: &amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; myInt;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Long: &amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; myLong;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Double: &amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; myDouble;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Float: &amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; myFloat;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Unsigned: &amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; myUnsigned;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\n\nInt:\t&amp;quot; &amp;lt;&amp;lt; myInt &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Long:\t&amp;quot; &amp;lt;&amp;lt; myLong &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Double:\t&amp;quot; &amp;lt;&amp;lt; myDouble &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Float:\t&amp;quot; &amp;lt;&amp;lt; myFloat &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Unsigned:\t&amp;quot; &amp;lt;&amp;lt; myUnsigned &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==cin with strings (cin.getline)==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream.h&amp;gt;&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
  char mybuffer [100];&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;What&amp;quot;s your name? &amp;quot;;&lt;br /&gt;
  cin.getline (mybuffer,100);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Hello &amp;quot; &amp;lt;&amp;lt; mybuffer &amp;lt;&amp;lt; &amp;quot;.\n&amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Which is your favourite team? &amp;quot;;&lt;br /&gt;
  cin.getline (mybuffer,100);&lt;br /&gt;
  cout &amp;lt;&amp;lt; mybuffer;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;What&amp;quot;s your name? Joe&lt;br /&gt;
Hello Joe.&lt;br /&gt;
Which is your favourite team? Ea&lt;br /&gt;
Ea&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Concatenate put()==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   cout.put(&amp;quot;H&amp;quot;).put(&amp;quot;e&amp;quot;).put(&amp;quot;l&amp;quot;).put(&amp;quot;l&amp;quot;).put(&amp;quot;o&amp;quot;).put(&amp;quot;\n&amp;quot;);&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Contrasting input of a string via cin and cin.get==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cin;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   const int SIZE = 80;&lt;br /&gt;
   char buffer1[ SIZE ];&lt;br /&gt;
   char buffer2[ SIZE ];&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a sentence:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cin &amp;gt;&amp;gt; buffer1;&lt;br /&gt;
   cout &amp;lt;&amp;lt; buffer1 &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;&lt;br /&gt;
 &lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a sentence:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cin.get( buffer2, SIZE );&lt;br /&gt;
   cout &amp;lt;&amp;lt; buffer2 &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter a sentence:&lt;br /&gt;
This is a sentence.&lt;br /&gt;
This&lt;br /&gt;
Enter a sentence:&lt;br /&gt;
 is a sentence.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Contrasting input of a string with cin and cin.get.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   const int SIZE = 80;&lt;br /&gt;
   char buffer1[ SIZE ], buffer2[ SIZE ];&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a sentence:\n&amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; buffer1;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nThe string read with cin was:\n&amp;quot;&lt;br /&gt;
        &amp;lt;&amp;lt; buffer1 &amp;lt;&amp;lt; &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
   cin.get( buffer2, SIZE );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;The string read with cin.get was:\n&amp;quot; &lt;br /&gt;
        &amp;lt;&amp;lt; buffer2 &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Copy all standard input to standard output==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
int main ()&lt;br /&gt;
{&lt;br /&gt;
    // copy all standard input to standard output&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; std::cin.rdbuf();&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;asdf&lt;br /&gt;
asdf&lt;br /&gt;
asdf&lt;br /&gt;
asdf&lt;br /&gt;
fdsa&lt;br /&gt;
fdsa&lt;br /&gt;
Terminate batch job (Y/N)? n&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Demonstrating member function width==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cin;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   int widthValue = 4;&lt;br /&gt;
   char sentence[ 10 ];&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a sentence:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cin.width( 5 );&lt;br /&gt;
   cin &amp;gt;&amp;gt; sentence;&lt;br /&gt;
   cout &amp;lt;&amp;lt; sentence &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter a sentence:&lt;br /&gt;
This is a sentence.&lt;br /&gt;
This&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Extends std::streambuf to create data buffer==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;cstdio&amp;gt;&lt;br /&gt;
#include &amp;lt;cstring&amp;gt;&lt;br /&gt;
#include &amp;lt;streambuf&amp;gt;&lt;br /&gt;
// for read():&lt;br /&gt;
#ifdef _MSC_VER&lt;br /&gt;
# include &amp;lt;io.h&amp;gt;&lt;br /&gt;
#else&lt;br /&gt;
# include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#endif&lt;br /&gt;
class inbuf : public std::streambuf {&lt;br /&gt;
  protected:&lt;br /&gt;
    /* data buffer:&lt;br /&gt;
     * - at most, four characters in putback area plus&lt;br /&gt;
     * - at most, six characters in ordinary read buffer&lt;br /&gt;
     */&lt;br /&gt;
    static const int bufferSize = 10;    // size of the data buffer&lt;br /&gt;
    char buffer[bufferSize];             // data buffer&lt;br /&gt;
  public:&lt;br /&gt;
    /* constructor&lt;br /&gt;
     * - initialize empty data buffer&lt;br /&gt;
     * - no putback area&lt;br /&gt;
     * =&amp;gt; force underflow()&lt;br /&gt;
     */&lt;br /&gt;
    inbuf() {&lt;br /&gt;
        setg (buffer+4,     // beginning of putback area&lt;br /&gt;
              buffer+4,     // read position&lt;br /&gt;
              buffer+4);    // end position&lt;br /&gt;
    }&lt;br /&gt;
  protected:&lt;br /&gt;
    // insert new characters into the buffer&lt;br /&gt;
    virtual int_type underflow () {&lt;br /&gt;
        // is read position before end of buffer?&lt;br /&gt;
        if (gptr() &amp;lt; egptr()) {&lt;br /&gt;
            return traits_type::to_int_type(*gptr());&lt;br /&gt;
        }&lt;br /&gt;
        /* process size of putback area&lt;br /&gt;
         * - use number of characters read&lt;br /&gt;
         * - but at most four&lt;br /&gt;
         */&lt;br /&gt;
        int numPutback;&lt;br /&gt;
        numPutback = gptr() - eback();&lt;br /&gt;
        if (numPutback &amp;gt; 4) {&lt;br /&gt;
            numPutback = 4;&lt;br /&gt;
        }&lt;br /&gt;
        /* copy up to four characters previously read into&lt;br /&gt;
         * the putback buffer (area of first four characters)&lt;br /&gt;
         */&lt;br /&gt;
        std::memmove (buffer+(4-numPutback), gptr()-numPutback,&lt;br /&gt;
                      numPutback);&lt;br /&gt;
        // read new characters&lt;br /&gt;
        int num;&lt;br /&gt;
        num = read (0, buffer+4, bufferSize-4);&lt;br /&gt;
        if (num &amp;lt;= 0) {&lt;br /&gt;
            // ERROR or EOF&lt;br /&gt;
            return EOF;&lt;br /&gt;
        }&lt;br /&gt;
        // reset buffer pointers&lt;br /&gt;
        setg (buffer+(4-numPutback),   // beginning of putback area&lt;br /&gt;
              buffer+4,                // read position&lt;br /&gt;
              buffer+4+num);           // end of buffer&lt;br /&gt;
        // return next character&lt;br /&gt;
        return traits_type::to_int_type(*gptr());&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    inbuf ib;                // create special stream buffer&lt;br /&gt;
    std::istream in(&amp;amp;ib);    // initialize input stream with that buffer&lt;br /&gt;
    char c;&lt;br /&gt;
    for (int i=1; i&amp;lt;=20; i++) {&lt;br /&gt;
        // read next character (out of the buffer)&lt;br /&gt;
        in.get(c);&lt;br /&gt;
        // print that character (and flush)&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; c &amp;lt;&amp;lt; std::flush;&lt;br /&gt;
        // after eight characters, put two characters back into the stream&lt;br /&gt;
        if (i == 8) {&lt;br /&gt;
            in.unget();&lt;br /&gt;
            in.unget();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;a&lt;br /&gt;
a&lt;br /&gt;
d&lt;br /&gt;
d&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Is it a bad input==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
#include &amp;lt;cmath&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{  &lt;br /&gt;
   double area;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Please enter the area of a square: &amp;quot;;&lt;br /&gt;
   cin &amp;gt;&amp;gt; area;&lt;br /&gt;
   if (cin.fail())&lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Error: Bad input\n&amp;quot;;&lt;br /&gt;
      return 1;&lt;br /&gt;
   }&lt;br /&gt;
   if (area &amp;lt; 0)&lt;br /&gt;
   {&lt;br /&gt;
      cout &amp;lt;&amp;lt; &amp;quot;Error: Negative area.\n&amp;quot;;&lt;br /&gt;
      return 1;&lt;br /&gt;
   }&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;The side length is &amp;quot; &amp;lt;&amp;lt; sqrt(area) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Manipulator that skips until end-of-line==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;set&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;limits&amp;gt;&lt;br /&gt;
template &amp;lt;class charT, class traits&amp;gt;&lt;br /&gt;
inline&lt;br /&gt;
std::basic_istream&amp;lt;charT,traits&amp;gt;&amp;amp;&lt;br /&gt;
ignoreLine (std::basic_istream&amp;lt;charT,traits&amp;gt;&amp;amp; strm)&lt;br /&gt;
{&lt;br /&gt;
    // skip until end-of-line&lt;br /&gt;
    strm.ignore(std::numeric_limits&amp;lt;int&amp;gt;::max(),strm.widen(&amp;quot;\n&amp;quot;));&lt;br /&gt;
    // return stream for concatenation&lt;br /&gt;
    return strm;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    int i;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;read int and ignore rest of the line&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cin &amp;gt;&amp;gt; i;&lt;br /&gt;
    // ignore the rest of the line&lt;br /&gt;
    std::cin &amp;gt;&amp;gt; ignoreLine;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;int: &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;read int and ignore two lines&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cin &amp;gt;&amp;gt; i;&lt;br /&gt;
    // ignore two lines&lt;br /&gt;
    std::cin &amp;gt;&amp;gt; ignoreLine &amp;gt;&amp;gt; ignoreLine;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;int: &amp;quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;read int and ignore rest of the line&lt;br /&gt;
123 qwe&lt;br /&gt;
int: 123&lt;br /&gt;
read int and ignore two lines&lt;br /&gt;
123wer&lt;br /&gt;
asdf&lt;br /&gt;
int: 123&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Read a character from keyboard==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;/* The following code example is taken from the book&lt;br /&gt;
 * &amp;quot;The C++ Standard Library - A Tutorial and Reference&amp;quot;&lt;br /&gt;
 * by Nicolai M. Josuttis, Addison-Wesley, 1999&lt;br /&gt;
 *&lt;br /&gt;
 * (C) Copyright Nicolai M. Josuttis 1999.&lt;br /&gt;
 * Permission to copy, use, modify, sell and distribute this software&lt;br /&gt;
 * is granted provided this copyright notice appears in all copies.&lt;br /&gt;
 * This software is provided &amp;quot;as is&amp;quot; without express or implied&lt;br /&gt;
 * warranty, and with no claim as to its suitability for any purpose.&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    char c;&lt;br /&gt;
    // while it is possible to read a character&lt;br /&gt;
    while (cin.get(c)) {&lt;br /&gt;
        // print it&lt;br /&gt;
        cout.put(c);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;a&lt;br /&gt;
a&lt;br /&gt;
c&lt;br /&gt;
c&lt;br /&gt;
d&lt;br /&gt;
d&lt;br /&gt;
e&lt;br /&gt;
e&lt;br /&gt;
Terminate batch job (Y/N)? n&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Read char array from keyboard, get its length and concatenate two strings==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
using std::cout;       &lt;br /&gt;
using std::cin;&lt;br /&gt;
int main() &lt;br /&gt;
{&lt;br /&gt;
  char firststring[40],secondstring[40],thirdstring[40];&lt;br /&gt;
  int size;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Please enter a word \n&amp;quot;;&lt;br /&gt;
  cin.getline(firststring,40); &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Please enter another word  \n&amp;quot;;&lt;br /&gt;
  cin.getline(secondstring,40);&lt;br /&gt;
  size = strlen(firststring);&lt;br /&gt;
 &lt;br /&gt;
  strcat(firststring,secondstring);&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;The length of the first string you entered is&amp;quot; &amp;lt;&amp;lt; size &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Both strings you entered are &amp;quot; &amp;lt;&amp;lt; thirdstring&amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Please enter a word&lt;br /&gt;
word&lt;br /&gt;
Please enter another word&lt;br /&gt;
word&lt;br /&gt;
The length of the first string you entered is4&lt;br /&gt;
Both strings you entered are  ?&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Read int value from keyboard==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Enter a number: &amp;quot;; &lt;br /&gt;
  int a; // declare one variable &lt;br /&gt;
  cin &amp;gt;&amp;gt; a; &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Enter a second number: &amp;quot;; &lt;br /&gt;
  int b; // declare another variable &lt;br /&gt;
  cin &amp;gt;&amp;gt; b; &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Product: &amp;quot; &amp;lt;&amp;lt; a*b &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter a number: 123&lt;br /&gt;
Enter a second number: 12&lt;br /&gt;
Product: 1476&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing error states.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cin;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   int integerValue;&lt;br /&gt;
   // display results of cin functions&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Before a bad input operation:&amp;quot;&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\ncin.rdstate(): &amp;quot; &amp;lt;&amp;lt; cin.rdstate()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n    cin.eof(): &amp;quot; &amp;lt;&amp;lt; cin.eof()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n   cin.fail(): &amp;quot; &amp;lt;&amp;lt; cin.fail()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n    cin.bad(): &amp;quot; &amp;lt;&amp;lt; cin.bad()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n   cin.good(): &amp;quot; &amp;lt;&amp;lt; cin.good();&lt;br /&gt;
   cin &amp;gt;&amp;gt; integerValue;&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;After a bad input operation:&amp;quot;&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\ncin.rdstate(): &amp;quot; &amp;lt;&amp;lt; cin.rdstate()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n    cin.eof(): &amp;quot; &amp;lt;&amp;lt; cin.eof()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n   cin.fail(): &amp;quot; &amp;lt;&amp;lt; cin.fail()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n    cin.bad(): &amp;quot; &amp;lt;&amp;lt; cin.bad()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\n   cin.good(): &amp;quot; &amp;lt;&amp;lt; cin.good() &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cin.clear();&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;After cin.clear()&amp;quot; &amp;lt;&amp;lt; &amp;quot;\ncin.fail(): &amp;quot; &amp;lt;&amp;lt; cin.fail()&lt;br /&gt;
      &amp;lt;&amp;lt; &amp;quot;\ncin.good(): &amp;quot; &amp;lt;&amp;lt; cin.good() &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Before a bad input operation:&lt;br /&gt;
cin.rdstate(): 0&lt;br /&gt;
    cin.eof(): 0&lt;br /&gt;
   cin.fail(): 0&lt;br /&gt;
    cin.bad(): 0&lt;br /&gt;
   cin.good(): 12&lt;br /&gt;
After a bad input operation:&lt;br /&gt;
cin.rdstate(): 0&lt;br /&gt;
    cin.eof(): 0&lt;br /&gt;
   cin.fail(): 0&lt;br /&gt;
    cin.bad(): 0&lt;br /&gt;
   cin.good(): 1&lt;br /&gt;
After cin.clear()&lt;br /&gt;
cin.fail(): 0&lt;br /&gt;
cin.good(): 1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Unformatted I/O using cin.read, cin.gcount and cout.write==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using std::cin;&lt;br /&gt;
using std::cout;&lt;br /&gt;
using std::endl;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   const int SIZE = 80;&lt;br /&gt;
   char buffer[ SIZE ];&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a sentence:&amp;quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
   cin.read( buffer, 20 );&lt;br /&gt;
   cout.write( buffer, cin.gcount() );&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter a sentence:&lt;br /&gt;
This is a sentence.&lt;br /&gt;
This is a sentence.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Unformatted I/O with read, gcount and write.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   const int SIZE = 80;&lt;br /&gt;
   char buffer[ SIZE ];&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Enter a sentence:\n&amp;quot;;&lt;br /&gt;
   cin.read( buffer, 20 );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nThe sentence entered was:\n&amp;quot;;&lt;br /&gt;
   cout.write( buffer, cin.gcount() );&lt;br /&gt;
   cout &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use get() to read a string that contains spaces==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
#include &amp;lt;fstream&amp;gt; &lt;br /&gt;
using namespace std; &lt;br /&gt;
 &lt;br /&gt;
int main() &lt;br /&gt;
{ &lt;br /&gt;
  char str[80]; &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; &amp;quot;Enter your name: &amp;quot;; &lt;br /&gt;
  cin.get(str, 79); &lt;br /&gt;
 &lt;br /&gt;
  cout &amp;lt;&amp;lt; str &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
 &lt;br /&gt;
  return 0; &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter your name: Joe&lt;br /&gt;
Joe&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use the extraction operator &amp;gt;&amp;gt; with cin.get( ) to process an entire string.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
#define INUMCHARS 45&lt;br /&gt;
#define INULL_CHARACTER 1&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
 char pname[INUMCHARS + INULL_CHARACTER];&lt;br /&gt;
 cout &amp;lt;&amp;lt; &amp;quot;Please enter your first and last name: &amp;quot;;&lt;br /&gt;
 cin.get(pname,INUMCHARS);&lt;br /&gt;
 cout &amp;lt;&amp;lt; &amp;quot;\n\nThank you, &amp;quot; &amp;lt;&amp;lt; pname;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using member functions get, put and eof.==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char c;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;Before input, cin.eof() is &amp;quot; &amp;lt;&amp;lt; cin.eof()&lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot;\nEnter a sentence followed by end-of-file:\n&amp;quot;;&lt;br /&gt;
   while ( ( c = cin.get() ) != EOF )&lt;br /&gt;
      cout.put( c );&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nEOF in this system is: &amp;quot; &amp;lt;&amp;lt; c;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;\nAfter input, cin.eof() is &amp;quot; &amp;lt;&amp;lt; cin.eof() &amp;lt;&amp;lt; endl;&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using peek() and putback()==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char ch;&lt;br /&gt;
   cout &amp;lt;&amp;lt; &amp;quot;enter a phrase: &amp;quot;;&lt;br /&gt;
   while ( cin.get(ch) )&lt;br /&gt;
   {&lt;br /&gt;
      if (ch == &amp;quot;!&amp;quot;)&lt;br /&gt;
         cin.putback(&amp;quot;$&amp;quot;);&lt;br /&gt;
      else&lt;br /&gt;
         cout &amp;lt;&amp;lt; ch;&lt;br /&gt;
      while (cin.peek() == &amp;quot;#&amp;quot;)&lt;br /&gt;
         cin.ignore(1,&amp;quot;#&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
   return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>