본문 바로가기

CS/Algorithm

[C++] 파일의 끝(EOF)까지 입력받기

정수

#include <iostream>    //cin.eof()

using namespace std;

int main() {
    int n;
    while (!cin.eof()) {    //EOF를 만날때까지 무한 입력
        cin >> n;
    }

    return 0;
}

string(문자열)

#include <iostream>

using namespace std;

int main(){
    string s;
    while(getline(cin, s)){

    }

    return 0;
}

이 밖에도 다양한 방법이 있는 것 같지만 일단 이정도로 알아보도록 하자.

'CS > Algorithm' 카테고리의 다른 글

[C++] 데큐(DEQUE)  (0) 2023.09.30
[C++] 우선순위 큐(PRIORITY_QUEUE)  (0) 2023.09.30
[C++] 스택(STACK)  (0) 2023.09.30
[C++] 자료형에 따른 숫자 범위  (0) 2023.09.30
[C++] 구조체(STRUCT)  (0) 2023.09.30