Namespaces
Variants

std::basic_ifstream<CharT,Traits>:: is_open

From cppreference.net

bool is_open ( ) const ;

파일 스트림이 연결된 파일을 가지고 있는지 확인합니다.

효과적으로 rdbuf()->is_open() 를 호출합니다.

목차

매개변수

(없음)

반환값

true 파일 스트림에 연결된 파일이 있을 경우, false 그렇지 않을 경우.

예제

#include <fstream>
#include <iostream>
#include <string>
// this file is called main.cpp
bool file_exists(const std::string& str)
{
    std::ifstream fs(str);
    return fs.is_open();
}
int main()
{
    std::boolalpha(std::cout);
    std::cout << file_exists("main.cpp")  << '\n'
              << file_exists("strange_file") << '\n';
}

가능한 출력:

true
false

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 365 C++98 is_open const 한정자로 선언되지 않음 const 한정자로 선언됨

참고 항목

파일을 열고 스트림과 연결합니다
(public member function)
연결된 파일을 닫습니다
(public member function)