Namespaces
Variants

std:: basic_stringstream

From cppreference.net
< cpp ‎ | io
헤더 파일에 정의됨 <sstream>
template <

class CharT,
class Traits = std:: char_traits < CharT > ,
class Allocator = std:: allocator < CharT >
> class basic_stringstream

: public basic_iostream < CharT, Traits > ;

클래스 템플릿 std::basic_stringstream 은 문자열 기반 스트림에서의 입력 및 출력 연산을 구현합니다. 이는 std::basic_string 의 인스턴스를 효과적으로 저장하고 이를 기반으로 입력 및 출력 연산을 수행합니다.

저수준에서 이 클래스는 기본적으로 std::basic_stringbuf 의 원시 문자열 장치 구현을 std::basic_iostream 의 고수준 인터페이스로 감싸줍니다. std::basic_stringbuf 고유 멤버들에 대한 완전한 인터페이스가 제공됩니다.

cpp/io/ios base cpp/io/basic ios cpp/io/basic istream cpp/io/basic ostream cpp/io/basic iostream std-basic stringstream-inheritance.svg

상속 다이어그램

일반적인 문자 타입에 대한 여러 typedef가 제공됩니다:

헤더 파일에 정의됨 <sstream>
타입 정의
std::stringstream std :: basic_stringstream < char >
std::wstringstream std :: basic_stringstream < wchar_t >

목차

멤버 타입

멤버 타입 정의
char_type CharT
traits_type Traits ; Traits::char_type CharT 가 아닌 경우 프로그램은 ill-formed입니다.
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type
allocator_type Allocator

설명 전용 멤버

이름 정의
sb 기본 버퍼로 사용되는 std:: basic_stringbuf < CharT, Traits, Allocator >
( 설명 전용 멤버 객체* )

멤버 함수

string stream을 생성함
(public member function)
(C++11)
string stream을 이동함
(public member function)
(C++11)
두 string stream을 교환함
(public member function)
기반 raw string 장치 객체를 반환함
(public member function)
String operations
기반 string 장치 객체의 내용을 가져오거나 설정함
(public member function)
(C++20)
기반 string 장치 객체의 내용에 대한 view를 얻음
(public member function)

비멤버 함수

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_ostream 에서 상속됨

멤버 함수

형식화된 출력
형식화된 데이터를 삽입함
( std::basic_ostream<CharT,Traits> 의 public 멤버 함수)
비형식화된 출력
문자를 삽입함
( std::basic_ostream<CharT,Traits> 의 public 멤버 함수)
문자 블록을 삽입함
( std::basic_ostream<CharT,Traits> 의 public 멤버 함수)
위치 지정
출력 위치 표시자를 반환함
( std::basic_ostream<CharT,Traits> 의 public 멤버 함수)
출력 위치 표시자를 설정함
( std::basic_ostream<CharT,Traits> 의 public 멤버 함수)
기타
기본 저장 장치와 동기화함
( std::basic_ostream<CharT,Traits> 의 public 멤버 함수)

멤버 클래스

스트림 출력 작업 준비를 위한 기본 로직을 구현함
( std::basic_ostream<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 멤버 함수)
특정 형식 플래그 설정
( std::ios_base 의 public 멤버 함수)
특정 형식 플래그 해제
( std::ios_base 의 public 멤버 함수)
부동 소수점 연산의 소수점 정밀도 관리
( std::ios_base 의 public 멤버 함수)
필드 너비 관리
( std::ios_base 의 public 멤버 함수)
로캘
로캘 설정
( std::ios_base 의 public 멤버 함수)
현재 로캘 반환
( std::ios_base 의 public 멤버 함수)
내부 확장 가능 배열
[static]
pword() iword() 의 인덱스로 사용하기 안전한 프로그램 전체 고유 정수 반환
( std::ios_base 의 public static 멤버 함수)
필요한 경우 전용 저장소 크기 조정 및 지정된 인덱스의 long 요소 접근
( std::ios_base 의 public 멤버 함수)
필요한 경우 전용 저장소 크기 조정 및 지정된 인덱스의 void * 요소 접근
( std::ios_base 의 public 멤버 함수)
기타
이벤트 콜백 함수 등록
( std::ios_base 의 public 멤버 함수)
C++ 및 C I/O 라이브러리 상호 운용성 설정
( std::ios_base 의 public static 멤버 함수)
멤버 클래스
스트림 예외
( std::ios_base 의 public 멤버 클래스)
표준 스트림 객체 초기화
( std::ios_base 의 public 멤버 클래스)

멤버 타입 및 상수

타입 설명
스트림 열기 모드 타입

다음 상수들도 정의되어 있습니다:

상수 설명
app 각 쓰기 전에 스트림의 끝으로 이동
binary 바이너리 모드 로 열기
in 읽기용으로 열기
out 쓰기용으로 열기
trunc 열 때 스트림의 내용을 버림
ate 열자마자 스트림의 끝으로 이동
noreplace (C++23) 배타 모드로 열기

(typedef)
서식 플래그 타입

다음 상수들도 정의됩니다:

상수 설명
dec 정수 입출력에 10진법 사용: std::dec 참조
oct 정수 입출력에 8진법 사용: std::oct 참조
hex 정수 입출력에 16진법 사용: std::hex 참조
basefield dec | oct | hex . 마스킹 연산에 유용함
left 왼쪽 정렬 (오른쪽에 채움 문자 추가): std::left 참조
right 오른쪽 정렬 (왼쪽에 채움 문자 추가): std::right 참조
internal 내부 정렬 (내부 지정 지점에 채움 문자 추가): std::internal 참조
adjustfield left | right | internal . 마스킹 연산에 유용함
scientific 부동 소수점 타입을 과학적 표기법으로 생성하거나, fixed 와 결합 시 16진법 표기법 사용: std::scientific 참조
fixed 부동 소수점 타입을 고정 소수점 표기법으로 생성하거나, scientific 와 결합 시 16진법 표기법 사용: std::fixed 참조
floatfield scientific | fixed . 마스킹 연산에 유용함
boolalpha bool 타입을 영숫자 형식으로 삽입 및 추출: std::boolalpha 참조
showbase 정수 출력을 위한 숫자 체계 접두사 생성, 통화 입출력에서 통화 표시자 요구: std::showbase 참조
showpoint 부동 소수점 숫자 출력에서 무조건 소수점 문자 생성: std::showpoint 참조
showpos 음수가 아닌 숫자 출력에 + 문자 생성: std::showpos 참조
skipws 특정 입력 연산 전에 선행 공백 건너뜀: std::skipws 참조
unitbuf 각 출력 연산 후 출력 버퍼 플러시: std::unitbuf 참조
uppercase 특정 출력 연산에서 일부 소문자를 대문자로 대체: std::uppercase 참조

(typedef)
스트림 상태 타입

다음 상수들도 정의됩니다:

상수 설명
goodbit 오류 없음
badbit 복구 불가능한 스트림 오류
failbit 입출력 연산 실패 (형식화 또는 추출 오류)
eofbit 관련 입력 시퀀스가 파일 끝에 도달함

(typedef)
탐색 방향 타입

다음 상수들도 정의됩니다:

상수 설명
beg 스트림의 시작
end 스트림의 끝
cur 스트림 위치 지시자의 현재 위치

(typedef)
이벤트 타입 지정
(enum)
콜백 함수 타입
(typedef)