nakka soft world !
iostream, cin 본문
728x90
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n = 0;
cin >> n;
while(1) {
if(cin.fall())
{
cout << "입력실패" << endl;
// cin안에 있는 실패를 나타내는 멤버 데이터 초기화
cin.clear();
cin.ignore(); // 입력 버퍼하나를 비운다.
continue;
}
break;
}
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
cin >> s; //"hello world" 단어
cout << s << endl; // hello
getline(cin, s); // cin에서 한문장 입력
cout << s << endl; // hello world
}
728x90
'프로그래밍언어 > C++' 카테고리의 다른 글
[MFC] CString <-> string (0) | 2017.04.27 |
---|---|
C++ 파일 입출력 (0) | 2017.03.27 |
예외 (Exception) (0) | 2017.03.27 |
다중 상속 (multiple inheritance), 다이아몬드 상속 (0) | 2017.03.27 |
RTTI ( Rut Time Type Information ) , dynamic_cast (0) | 2017.03.27 |