다음을 통해 공유


cin

Specifies the cin global stream.

extern istream cin;

반환 값

istream 개체

설명

The object controls extractions from the standard input as a byte stream. Once the object is constructed, the call cin.tie returns &cout.

예제

In this example, cin sets the fail bit on the stream when it encounters non-numeric characters. The program clears the fail bit and strips the invalid character from the stream to proceed.

// iostream_cin.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

int main()
{
   int x;
   cout << "enter choice:";
   cin >> x;
   while (x < 1 || x > 4)
   {
      cout << "Invalid choice, try again:";
      cin >> x;
      // not a numeric character, probably
      // clear the failure and pull off the non-numeric character
      if (cin.fail())
      {
         cin.clear();
         char c;
         cin >> c;
      }
   }
}
  2

요구 사항

Header: <iostream>

네임스페이스: std

참고 항목

참조

istream

iostream 프로그래밍

iostreams 규칙