std:: basic_ifstream
|
헤더 파일에 정의됨
<fstream>
|
||
|
template
<
class
CharT,
|
||
클래스 템플릿
basic_ifstream
은 파일 기반 스트림에 대한 고수준 입력 연산을 구현합니다. 이는 파일 기반 스트림 버퍼(
std::basic_filebuf
)를 고수준 인터페이스(
std::basic_istream
)와 연결합니다.
std::basic_ifstream
의 일반적인 구현은 오직 하나의 비파생 데이터 멤버만을 보유합니다:
std::
basic_filebuf
<
CharT, Traits
>
의 인스턴스입니다.
상속 다이어그램
일반적인 문자 타입에 대한 여러 typedef가 제공됩니다:
|
헤더 파일에 정의됨
<fstream>
|
|
| 타입 | 정의 |
std::ifstream
|
std :: basic_ifstream < char > |
std::wifstream
|
std :: basic_ifstream < wchar_t > |
목차 |
멤버 타입
| 멤버 타입 | 정의 |
char_type
|
CharT
|
traits_type
|
Traits
; 프로그램이 잘못된 형식입니다 만약
Traits::char_type
가
CharT
가 아닌 경우.
|
int_type
|
Traits::int_type
|
pos_type
|
Traits::pos_type
|
off_type
|
Traits::off_type
|
native_handle_type
(C++26)
|
구현 정의
타입으로
TriviallyCopyable
이고
semiregular
입니다.
|
멤버 함수
|
파일 스트림을 생성함
(public member function) |
|
|
(destructor)
[virtual]
(implicitly declared)
|
basic_ifstream
및 관련 버퍼를 소멸시키고 파일을 닫음
(virtual public member function) |
|
(C++11)
|
파일 스트림을 이동함
(public member function) |
|
(C++11)
|
두 파일 스트림을 교환함
(public member function) |
|
기본 raw 파일 장치 객체를 반환함
(public member function) |
|
|
(C++26)
|
기본 구현 정의 핸들을 반환함
(public member function) |
파일 연산 |
|
|
스트림에 연결된 파일이 있는지 확인함
(public member function) |
|
|
파일을 열고 스트림과 연결함
(public member function) |
|
|
연결된 파일을 닫음
(public member function) |
|
비멤버 함수
|
(C++11)
|
std::swap
알고리즘을 특수화함
(함수 템플릿) |
std:: basic_istream 로부터 상속됨
멤버 함수
형식화된 입력 |
|
|
형식화된 데이터를 추출함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
비형식화된 입력 |
|
|
문자를 추출함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
다음 문자를 추출하지 않고 읽음
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
문자를 추출 취소함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
입력 스트림에 문자를 넣음
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
주어진 문자를 찾을 때까지 문자를 추출함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
주어진 문자를 찾을 때까지 문자를 추출하고 버림
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
문자 블록을 추출함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
이미 사용 가능한 문자 블록을 추출함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
마지막 비형식화 입력 작업으로 추출된 문자 수를 반환함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
위치 지정 |
|
|
입력 위치 표시자를 반환함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
|
입력 위치 표시자를 설정함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
기타 |
|
|
기본 저장 장치와 동기화함
(
std::basic_istream<CharT,Traits>
의 public 멤버 함수)
|
|
멤버 클래스
|
입력 작업을 위한 스트림 준비 기본 로직을 구현함
(
std::basic_istream<CharT,Traits>
의 public 멤버 클래스)
|
std:: basic_ios 로부터 상속됨
멤버 타입
| 멤버 타입 | 정의 |
char_type
|
CharT
|
traits_type
|
Traits
|
int_type
|
Traits::int_type
|
pos_type
|
Traits::pos_type
|
off_type
|
Traits::off_type
|
멤버 함수
상태 함수 |
|
|
오류가 발생하지 않았는지 확인합니다 (즉, I/O 작업을 사용할 수 있는 상태)
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
파일 끝에 도달했는지 확인합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
오류가 발생했는지 확인합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
복구 불가능한 오류가 발생했는지 확인합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
오류가 발생했는지 확인합니다 (
fail()
의 동의어)
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
오류가 발생하지 않았는지 확인합니다 (
!
fail()
의 동의어)
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
상태 플래그를 반환합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
상태 플래그를 설정합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
상태 플래그를 수정합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
서식 지정 |
|
|
서식 정보를 복사합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
채움 문자를 관리합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
기타 |
|
|
예외 마스크를 관리합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
로케일을 설정합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
연결된 스트림 버퍼를 관리합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
연결된 스트림을 관리합니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
문자를 좁힙니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
|
문자를 넓힙니다
(
std::basic_ios<CharT,Traits>
의 public 멤버 함수)
|
|
std:: ios_base 에서 상속됨
멤버 함수
서식 지정 |
|
|
형식 플래그 관리
(
std::ios_base
의 public member function)
|
|
|
특정 형식 플래그 설정
(
std::ios_base
의 public member function)
|
|
|
특정 형식 플래그 해제
(
std::ios_base
의 public member function)
|
|
|
부동 소수점 연산의 소수점 정밀도 관리
(
std::ios_base
의 public member function)
|
|
|
필드 너비 관리
(
std::ios_base
의 public member function)
|
|
로캘 |
|
|
로캘 설정
(
std::ios_base
의 public member function)
|
|
|
현재 로캘 반환
(
std::ios_base
의 public member function)
|
|
내부 확장 가능 배열 |
|
|
[static]
|
pword()
및
iword()
의 인덱스로 사용하기에 안전한 프로그램 전체 고유 정수 반환
(
std::ios_base
의 public static member function)
|
|
필요한 경우 전용 저장소 크기 조정 및 지정된 인덱스의
long
요소 접근
(
std::ios_base
의 public member function)
|
|
|
필요한 경우 전용 저장소 크기 조정 및 지정된 인덱스의
void
*
요소 접근
(
std::ios_base
의 public member function)
|
|
기타 |
|
|
이벤트 콜백 함수 등록
(
std::ios_base
의 public member function)
|
|
|
[static]
|
C++과 C I/O 라이브러리 상호 운용성 설정
(
std::ios_base
의 public static member function)
|
멤버 클래스 |
|
|
스트림 예외
(
std::ios_base
의 public member class)
|
|
|
표준 스트림 객체 초기화
(
std::ios_base
의 public member class)
|
|
멤버 타입과 상수 |
|||||||||||||||||||||||||||||||||||||||
| 유형 | 설명 | ||||||||||||||||||||||||||||||||||||||
|
스트림 열기 모드 타입
다음 상수들도 정의되어 있습니다:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
|
서식 플래그 타입
다음 상수들도 정의됩니다:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
|
스트림 상태 타입
다음 상수들도 정의됩니다:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
|
탐색 방향 타입
다음 상수들도 정의됩니다:
(typedef) |
|||||||||||||||||||||||||||||||||||||||
|
이벤트 타입 지정
(enum) |
|||||||||||||||||||||||||||||||||||||||
|
콜백 함수 타입
(typedef) |
|||||||||||||||||||||||||||||||||||||||
참고 사항
| Feature-test 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_fstream_native_handle
|
202306L
|
(C++26) | 네이티브 핸들 지원 |
예제
#include <fstream> #include <iostream> #include <string> int main() { std::string filename = "Test.b"; // 읽을 파일 준비 double d = 3.14; std::ofstream(filename, std::ios::binary) .write(reinterpret_cast<char*>(&d), sizeof d) << 123 << "abc"; // 파일을 읽기 위해 열기 std::ifstream istrm(filename, std::ios::binary); if (!istrm.is_open()) std::cout << "failed to open " << filename << '\n'; else { double d; istrm.read(reinterpret_cast<char*>(&d), sizeof d); // 바이너리 입력 int n; std::string s; if (istrm >> n >> s) // 텍스트 입력 std::cout << "read back from file: " << d << ' ' << n << ' ' << s << '\n'; } }
출력:
read back from file: 3.14 123 abc