nakka soft world !

iostream, cin 본문

프로그래밍언어/C++

iostream, cin

nakka 2017. 3. 27. 19:40
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
Comments