basic_ios 클래스

클래스 템플릿은 템플릿 매개 변수에 의존하는 입력 스트림(클래스 템플릿의) 및 출력 스트림(클래스 템플릿basic_istreambasic_ostream)에 공통적인 스토리지 및 멤버 함수를 설명합니다. (클래스 ios_base 는 템플릿 매개 변수에 종속되지 않고 일반적인 항목에 대해 설명합니다.) 클래스 basic_ios<class Elem, class Traits> 의 개체는 클래스에 의해 문자 특성이 결정되는 형식 Elem의 요소를 사용하여 스트림을 제어하는 Traits데 도움이 됩니다.

구문

template <class Elem, class Traits>
class basic_ios : public ios_base

매개 변수

Elem
문자 형식입니다.

Traits
문자 형식에 대한 정보를 제공하는 형식으로, 기본값은 .입니다 char_traits < Elem >.

설명

클래스 basic_ios<class Elem, class Traits> 저장소의 개체:

  • 형식 basic_istream<Elem, Traits>의 개체에 대한 연결 포인터입니다.

  • 형식 basic_streambuf<Elem, Traits >의 개체에 대한 스트림 버퍼 포인터입니다.

  • 서식 정보

  • 형식ios_base의 기본 개체에서 상태 정보를 스트리밍합니다.

  • char_type 형식의 개체에 있는 채우기 문자

자세한 내용은 basic_istreambasic_streambuf를 참조하세요.

생성자

생성자 Description
basic_ios basic_ios 클래스를 생성합니다.

Typedef

형식 이름 설명
char_type 템플릿 매개 변수 Elem의 동의어.
int_type Traits::int_type의 동의어입니다.
off_type Traits::off_type의 동의어입니다.
pos_type Traits::pos_type의 동의어입니다.
traits_type 템플릿 매개 변수 Traits의 동의어.

멤버 함수

멤버 함수 설명
bad 스트림 버퍼의 무결성 손실을 나타냅니다.
clear 오류 플래그를 모두 지웁니다.
copyfmt 스트림 간에 플래그를 복사합니다.
eof 스트림의 끝에 도달했는지 여부를 나타냅니다.
exceptions 스트림에서 발생하는 예외를 나타냅니다.
fail 스트림에서 유효한 필드 추출 실패를 나타냅니다.
fill 텍스트가 스트림만큼 넓지 않을 때 사용할 문자를 지정하거나 반환합니다.
good 스트림 상태가 양호함을 나타냅니다.
imbue 로캘을 변경합니다.
init basic_ios 생성자에 의해 호출됩니다.
move 스트림 버퍼에 대한 포인터를 제외하고 매개 변수의 모든 값을 현재 개체로 이동합니다.
narrow 지정된 char_type에 해당하는 char를 찾습니다.
rdbuf 스트림을 지정된 버퍼로 라우트합니다.
rdstate 플래그에 대한 비트 상태를 읽습니다.
set_rdbuf 이 스트림 개체에 대한 읽기 버퍼로 사용할 스트림 버퍼를 할당합니다.
setstate 추가 플래그를 설정합니다.
swap basic_ios 개체의 값을 다른 basic_ios 개체의 값으로 교환합니다. 스트림 버퍼에 대한 포인터는 교환되지 않습니다.
tie 한 스트림이 다른 스트림보다 먼저 처리되도록 합니다.
widen 지정된 char에 해당하는 char_type을 찾습니다.

연산자

연산자 설명
explicit operator bool basic_ios 개체를 bool로 사용할 수 있도록 합니다. 일반적이고 의도하지 않은 부작용을 방지하기 위해 자동 형식 변환이 사용되지 않습니다.
operator void * 스트림 상태가 여전히 양호한지 여부를 나타냅니다.
operator! 스트림이 나쁘지 않은지 나타냅니다.

요구 사항

헤더<ios>:

네임스페이스:std

basic_ios::bad

스트림 버퍼의 무결성 손실을 나타냅니다.

bool bad() const;

Return Value

rdstate & badbit가 0이 아닌 경우 true, 0인 경우 false입니다.

badbit에 대한 자세한 내용은 ios_base::iostate를 참조하세요.

예시

// basic_ios_bad.cpp
// compile with: /EHsc
#include <iostream>

int main( void )
{
    using namespace std;
    bool b = cout.bad( );
    cout << boolalpha;
    cout << b << endl;

    b = cout.good( );
    cout << b << endl;
}

basic_ios::basic_ios

basic_ios 클래스를 생성합니다.

explicit basic_ios(basic_streambuf<Elem,  Traits>* sb);
basic_ios();

매개 변수

sb
입력 또는 출력 요소를 저장할 표준 버퍼입니다.

설명

첫 번째 생성자는 호출 init(_ Sb)하여 멤버 개체를 초기화합니다. 보호된 두 번째 생성자는 멤버 개체를 초기화하지 않은 채 유지합니다. 나중에 호출하면 개체가 init 안전하게 제거되기 전에 개체를 초기화해야 합니다.

basic_ios::char_type

템플릿 매개 변수 Elem의 동의어.

typedef Elem char_type;

basic_ios::clear

오류 플래그를 모두 지웁니다.

void clear(iostate state = goodbit, bool reraise = false);
void clear(io_state state);

매개 변수

state
(선택 사항) 모든 플래그를 지워서 설정하려는 플래그입니다. 기본값은 goodbit입니다.

reraise
(선택 사항) 예외를 다시 발생시켜야 하는지 여부를 지정합니다. 기본값은 예외를 false 다시 발생시키지 않음)입니다.

설명

플래그goodbit는 , failbiteofbitbadbit. 를 badeof사용하여 이러한 플래그를 테스트합니다.goodfail

멤버 함수는 저장된 스트림 상태 정보를 다음 코드로 바꿉니다.

state | (rdbuf != 0 goodbit : badbit)

0이 아닌 경우 state&exceptions 클래스 failure의 개체를 throw합니다.

자세한 내용은 rdbufexceptions를 참조하세요.

예시

를 사용하는 clear예제를 참조 rdstate 하세요getline.

basic_ios::copyfmt

스트림 간에 플래그를 복사합니다.

basic_ios<Elem, Traits>& copyfmt(
const basic_ios<Elem, Traits>& right);

매개 변수

right
플래그를 복사하려는 스트림입니다.

Return Value

this 플래그를 복사할 스트림의 개체입니다.

설명

멤버 함수는 콜백 이벤트를 erase_event보고합니다. 그런 다음 채우기 문자, 타이 포인터 및 서식 정보로 *this 복사 right 합니다. 예외 마스크를 변경하기 전에 콜백 이벤트를 copyfmt_event보고합니다. 복사가 완료 state&exceptions 된 후 0이 아닌 경우 함수는 인수rdstate를 사용하여 효과적으로 호출 clear 합니다. *this를 반환합니다.

예시

// basic_ios_copyfmt.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

int main( )
{
    using namespace std;
    ofstream x( "test.txt" );
    int i = 10;

    x << showpos;
    cout << i << endl;
    cout.copyfmt( x );
    cout << i << endl;
}

basic_ios::eof

스트림의 끝에 도달했는지 여부를 나타냅니다.

bool eof() const;

Return Value

스트림의 끝에 도달한 경우 true, 아닌 경우 false입니다.

설명

멤버 함수는 0이 아닌 경우 rdstate& eofbit 반환 true 합니다. eofbit에 대한 자세한 내용은 ios_base::iostate를 참조하세요.

예시

// basic_ios_eof.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

using namespace std;

int main( int argc, char* argv[] )
{
    fstream   fs;
    int n = 1;
    fs.open( "basic_ios_eof.txt" );   // an empty file
    cout << boolalpha
    cout << fs.eof() << endl;
    fs >> n;   // Read the char in the file
    cout << fs.eof() << endl;
}

basic_ios::exceptions

스트림에서 발생하는 예외를 나타냅니다.

iostate exceptions() const;
void exceptions(iostate Newexcept);
void exceptions(io_state Newexcept);

매개 변수

Newexcept
예외를 throw하려는 플래그입니다.

Return Value

스트림에 대한 예외를 throw하도록 현재 지정된 플래그입니다.

설명

첫 번째 멤버 함수는 저장된 예외 마스크를 반환합니다. 두 번째 멤버 함수는 예외 마스크에 저장 _Except 되고 이전 저장된 값을 반환합니다. 새 예외 마스크를 저장하면 호출 clear( rdstate )과 같은 예외가 throw됩니다.

예시

// basic_ios_exceptions.cpp
// compile with: /EHsc /GR
#include <iostream>

int main( )
{
    using namespace std;

    cout << cout.exceptions( ) << endl;
    cout.exceptions( ios::eofbit );
    cout << cout.exceptions( ) << endl;
    try
    {
        cout.clear( ios::eofbit );   // Force eofbit on
    }
    catch ( exception &e )
    {
        cout.clear( );
        cout << "Caught the exception." << endl;
        cout << "Exception class: " << typeid(e).name()  << endl;
        cout << "Exception description: " << e.what() << endl;
    }
}
0
1
Caught the exception.
Exception class: class std::ios_base::failure
Exception description: ios_base::eofbit set

basic_ios::fail

스트림에서 유효한 필드 추출 실패를 나타냅니다.

bool fail() const;

Return Value

true 0이 아니면 0이 아닌 경우 rdstate & (badbit|failbit)false.

failbit에 대한 자세한 내용은 ios_base::iostate를 참조하세요.

예시

// basic_ios_fail.cpp
// compile with: /EHsc
#include <iostream>

int main( void )
{
    using namespace std;
    bool b = cout.fail( );
    cout << boolalpha;
    cout << b << endl;
}

basic_ios::fill

텍스트가 스트림만큼 넓지 않을 때 사용할 문자를 지정하거나 반환합니다.

char_type fill() const;
char_type fill(char_type Char);

매개 변수

Char
채우기 문자로 사용할 문자입니다.

Return Value

현재 채우기 문자입니다.

설명

첫 번째 멤버 함수는 저장된 채우기 문자를 반환합니다. 두 번째 멤버 함수는 채우기 문자에 Char을 저장하고 전에 저장된 값을 반환합니다.

예시

// basic_ios_fill.cpp
// compile with: /EHsc
#include <iostream>
#include <iomanip>

int main( )
{
    using namespace std;

    cout << setw( 5 ) << 'a' << endl;
    cout.fill( 'x' );
    cout << setw( 5 ) << 'a' << endl;
    cout << cout.fill( ) << endl;
}
a
xxxxa
x

basic_ios::good

스트림 상태가 양호함을 나타냅니다.

bool good() const;

Return Value

true (상태 플래그가 설정되지 않은 경우 rdstate == goodbit ) 그렇지 않으면 false.

goodbit에 대한 자세한 내용은 ios_base::iostate를 참조하세요.

예시

good 사용 예제는 basic_ios::bad를 참조하세요.

basic_ios::imbue

로캘을 변경합니다.

locale imbue(const locale& Loc);

매개 변수

Loc
로캘 문자열입니다.

Return Value

이전 로캘입니다.

설명

포인터가 NULL 아닌 경우 rdbuf 멤버 함수가 호출합니다.

rdbuf-> pubimbue(_ Loc)

어떤 경우든 ios_base::imbue(_ Loc)을 반환합니다.

자세한 내용은 pubimbueios_base::imbue를 참조하세요.

예시

// basic_ios_imbue.cpp
// compile with: /EHsc
#include <iostream>
#include <locale>

int main( )
{
    using namespace std;

    cout.imbue( locale( "french_france" ) );
    double x = 1234567.123456;
    cout << x << endl;
}

basic_ios::init

basic_ios 생성자에 의해 호출됩니다.

void init(basic_streambuf<Elem,Traits>* _Sb, bool _Isstd = false);

매개 변수

_Sb
입력 또는 출력 요소를 저장할 표준 버퍼입니다.

_Isstd
표준 스트림인지 여부를 지정합니다.

설명

멤버 함수는 모든 멤버 개체에 값을 저장하므로:

  • rdbuf은(는) _Sb을(를) 반환합니다.

  • tie 는 포인터를 NULL 반환합니다.

  • rdstate가 0이 아니면 _Sb 반환 goodbit 되고, 그렇지 않으면 반환됩니다badbit.

  • exceptions은(는) goodbit을(를) 반환합니다.

  • flags은(는) skipws | dec을(를) 반환합니다. 자세한 내용은 skipwsdec를 참조하세요.

  • width 는 0을 반환합니다.

  • precision 는 6을 반환합니다.

  • fill 는 공백 문자를 반환합니다.

  • getloc은(는) locale::classic을(를) 반환합니다.

  • iword 는 0을 반환하고 pword 모든 인수 값에 대한 포인터를 반환 NULL 합니다.

basic_ios::int_type

traits_type::int_type의 동의어입니다.

typedef typename traits_type::int_type int_type;

basic_ios::move

스트림 버퍼에 대한 포인터를 제외하고 매개 변수의 모든 값을 현재 개체로 이동합니다.

void move(basic_ios&& right);

매개 변수

right
값을 이동할 ios_base 개체입니다.

설명

보호된 멤버 함수는 저장된 right*this 값을 제외한 stream buffer pointer모든 값을 이동합니다. 이 값은 변경되지 않고 right 포인터*thisNULL 설정됩니다. 저장된 tie pointer 포인터가 .에서 포인터로 NULL 설정됩니다 right.

basic_ios::narrow

지정된 char_type에 해당하는 char를 찾습니다.

char narrow(char_type Char, char Default = '\0') const;

매개 변수

Char
변환할 char입니다.

Default
등가가 없는 경우 반환되도록 할 char입니다.

Return Value

지정된 char_type에 대한 등가 char입니다.

설명

멤버 함수는 use_facet<ctype<E>>(getloc()).narrow(Char, Default)를 반환합니다.

자세한 내용은 use_facetgetloc를 참조하세요.

예시

// basic_ios_narrow.cpp
// compile with: /EHsc
#include <ios>
#include <iostream>
#include <wchar.h>

int main( )
{
    using namespace std;
    wchar_t *x = L"test";
    char y[10];
    cout << x[0] << endl;
    wcout << x << endl;
    y[0] = wcout.narrow( x[0] );
    cout << y[0] << endl;
}

basic_ios::off_type

traits_type::off_type의 동의어입니다.

typedef typename traits_type::off_type off_type;

basic_ios::operator void *

스트림 상태가 여전히 양호한지 여부를 나타냅니다.

operator void *() const;

Return Value

연산자는 포인터를 반환합니다 NULLfail.

예시

// basic_ios_opgood.cpp
// compile with: /EHsc
#include <iostream>

int main( )
{
    using namespace std;
    cout << (bool)(&cout != 0) << endl;   // Stream is still good
}
1

basic_ios::operator!

스트림이 나쁘지 않은지 나타냅니다.

bool operator!() const;

Return Value

호출과 동일한 값을 반환합니다. basic_ios::fail

예시

// basic_ios_opbad.cpp
// compile with: /EHsc
#include <iostream>

int main( )
{
    using namespace std;
    cout << !cout << endl;   // Stream is not bad
}
0

basic_ios::operator bool

basic_ios 개체를 bool로 사용할 수 있도록 합니다. 일반적이고 의도하지 않은 부작용을 방지하기 위해 자동 형식 변환이 사용되지 않습니다.

explicit operator bool() const;

설명

스트림에 오류가 없으면 반환하고, 그렇지 않으면 false반환 true 합니다.

basic_ios::pos_type

traits_type::pos_type의 동의어입니다.

typedef typename traits_type::pos_type pos_type;

basic_ios::rdbuf

스트림을 지정된 버퍼로 라우트합니다.

basic_streambuf<Elem, Traits> *rdbuf() const;
basic_streambuf<Elem, Traits> *rdbuf(
basic_streambuf<Elem, Traits>* _Sb);

매개 변수

_Sb
스트림입니다.

설명

첫 번째 멤버 함수는 저장된 스트림 버퍼 포인터를 반환합니다.

두 번째 멤버 함수는 저장된 스트림 버퍼 포인터에 _Sb를 저장하고 전에 저장된 값을 반환합니다.

예시

// basic_ios_rdbuf.cpp
// compile with: /EHsc
#include <ios>
#include <iostream>
#include <fstream>

int main( )
{
    using namespace std;
    ofstream file( "rdbuf.txt" );
    streambuf *x = cout.rdbuf( file.rdbuf( ) );
    cout << "test" << endl;   // Goes to file
    cout.rdbuf(x);
    cout << "test2" << endl;
}
test2

basic_ios::rdstate

스트림 오류 상태를 읽습니다.

iostate rdstate() const;

Return Value

저장된 스트림 상태 정보입니다.

예시

// basic_ios_rdstate.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>
using namespace std;

void TestFlags( ios& x )
{
    cout << ( x.rdstate( ) & ios::badbit ) << endl;
    cout << ( x.rdstate( ) & ios::failbit ) << endl;
    cout << ( x.rdstate( ) & ios::eofbit ) << endl;
    cout << endl;
}

int main( )
{
    fstream x( "c:\test.txt", ios::out );
    x.clear( );
    TestFlags( x );
    x.clear( ios::badbit | ios::failbit | ios::eofbit );
    TestFlags( x );
}
0
0
0

4
2
1

basic_ios::setstate

지정된 스트림 오류 플래그(현재 스트림 오류 상태 플래그 다시 설정기본 변경되지 않음)를 설정합니다.

flag 설명
goodbit 오류 없음
badbit 복구할 수 없는 오류
failbit 형식 지정 또는 추출 오류와 같은 I/O 작업이 실패했습니다.
eofbit 스트림이 파일의 끝에 도달했습니다.
void setstate(iostate _State);

매개 변수

_State
설정할 추가 플래그입니다.

설명

멤버 함수는 기본적으로 .를 호출합니다 clear(_ state | rdstate).

자세한 내용은 clearrdstate를 참조하세요.

예시

// basic_ios_setstate.cpp
// compile with: /EHsc
#include <ios>
#include <iostream>
using namespace std;

int main( )
{
    bool b = cout.bad( );
    cout << b << endl;   // Good
    cout.clear( ios::badbit );
    b = cout.bad( );
    // cout.clear( );
    cout << b << endl;   // Is bad, good
    b = cout.fail( );
    cout << b << endl;   // Not failed
    cout.setstate( ios::failbit );
    b = cout.fail( );
    cout.clear( );
    cout << b << endl;   // Is failed, good
    return 0;
}
0
1

basic_ios::set_rdbuf

이 스트림 개체에 대한 읽기 버퍼로 사용할 스트림 버퍼를 할당합니다.

void set_rdbuf(
basic_streambuf<Elem, Tr>* strbuf)

매개 변수

strbuf
읽기 버퍼가 될 스트림 버퍼입니다.

설명

보호된 멤버 함수는 스트림 버퍼 포인터에 저장됩니다 strbuf . 호출 clear하지 않습니다.

basic_ios::tie

한 스트림이 다른 스트림보다 먼저 처리되도록 합니다.

basic_ostream<Elem, Traits> *tie() const;
basic_ostream<Elem, Traits> *tie(
basic_ostream<Elem, Traits>* str);

매개 변수

str
스트림입니다.

Return Value

첫 번째 멤버 함수는 저장된 연결(tie) 포인터를 반환합니다. 두 번째 멤버 함수는 연결(tie) 포인터에 str을 저장하고 전에 저장된 값을 반환합니다.

설명

tie는 한 스트림의 작업이 완료된 후 다른 스트림의 작업이 발생하도록 두 스트림을 동기화합니다.

예시

다음 예제에서는 문자열을 연결 cin 하여 cout숫자 자체가 추출되기 전에 콘솔로 이동하도록 보장 Enter a number: 합니다 cin. 이렇게 하면 숫자를 읽을 때 "숫자 입력:" 문자열이 버퍼에 계속 있을 가능성이 없으므로 사용자가 실제로 응답하라는 메시지가 표시될 수 있습니다. 기본적으로 cincout 연결됩니다.

#include <ios>
#include <iostream>

int main( )
{
    using namespace std;
    int i;
    cin.tie( &cout );
    cout << "Enter a number:";
    cin >> i;
}

basic_ios::traits_type

템플릿 매개 변수 Traits의 동의어.

typedef Traits traits_type;

basic_ios::widen

지정된 char에 해당하는 char_type을 찾습니다.

char_type widen(char Char) const;

매개 변수

Char
변환할 문자입니다.

Return Value

지정된 char에 해당하는 char_type을 찾습니다.

설명

멤버 함수는 use_facet<ctype<E>>(getloc).widen(Char)를 반환합니다.

자세한 내용은 use_facetgetloc를 참조하세요.

예시

// basic_ios_widen.cpp
// compile with: /EHsc
#include <ios>
#include <iostream>
#include <wchar.h>

int main( )
{
    using namespace std;
    char *z = "Hello";
    wchar_t y[2] = {0,0};
    cout << z[0] << endl;
    y[0] = wcout.widen( z[0] );
    wcout << &y[0] << endl;
}

basic_ios::swap

basic_ios 개체의 값을 다른 basic_ios 개체의 값으로 교환합니다. 그러나 스트림 버퍼에 대한 포인터는 교환되지 않습니다.

void swap(basic_ios&& right);

매개 변수

right
값을 교환하는 데 사용되는 basic_ios 개체입니다.

설명

보호된 멤버 함수는 저장된 stream buffer pointer를 제외하고 right에 저장된 모든 값을 *this와 교환합니다.

참고 항목

C++ 표준 라이브러리의 스레드 보안
iostream 프로그래밍
iostreams 규칙