Share via


<ios> 関数

boolalpha

bool 型の変数をストリームで truefalse として表示するように指定します。

ios_base& boolalpha(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、bool 型の変数は 1 または 0 として表示されます。

boolalpha は実質的に str.setf( ios_base::boolalpha) を呼び出し、str を返します。

noboolalphaboolalpha の実行結果を元に戻します。

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

int main( )
{
   using namespace std;
   bool b = true;
   cout << b << endl;
   boolalpha( cout );
   cout << b << endl;
   noboolalpha( cout );
   cout << b << endl;
   cout << boolalpha << b << endl;
}
1
true
1
true

12 月

整数変数を 10 進表記で表示するように指定します。

ios_base& dec(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、整数変数は、10 進表記で表示されます。

dec は実質的に str.setf( ios_base::dec, ios_base::basefield) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   int i = 100;

   cout << i << endl;   // Default is base 10
   cout << hex << i << endl;
   dec( cout );
   cout << i << endl;
   oct( cout );
   cout << i << endl;
   cout << dec << i << endl;
}
100
64
100
144
100

defaultfloat

浮動小数値に既定の表示形式を使用するように、ios_base オブジェクトのフラグを構成します。

ios_base& defaultfloat(ios_base& iosbase);

パラメーター

_Iosbase
ios_base オブジェクト。

解説

マニピュレーターは実質的に iosbase.ios_base::unsetf(ios_base::floatfield) を呼び出し、iosbase を返します。

修正済み

浮動小数点数を固定 10 進表記で表示するように指定します。

ios_base& fixed(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

fixed は浮動小数点数の既定の表示の表記です。 scientific は、浮動小数点数を指数表記を使用して表示します。

マニピュレーターは実質的に str.setf( ios_base::fixed, ios_base::floatfield ) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   float i = 1.1F;

   cout << i << endl;   // fixed is the default
   cout << scientific << i << endl;
   cout.precision( 1 );
   cout << fixed << i << endl;
}
1.1
1.100000e+000
1.1

hex

整数変数を 16 進表記で表示するように指定します。

ios_base& hex(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、整数変数は、10 進表記で表示されます。 dec および oct も整数変数の表示方法を変更します。

マニピュレーターは実質的に str.setf( ios_base::hex, ios_base::basefield) を呼び出し、str を返します。

hex の使用例については、「dec」を参照してください。

hexfloat

ios_base& hexfloat (ios_base& str);

io_errc

enum class io_errc {
    stream = 1
};

internal

数値の符号を左揃え、数値を右揃えにします。

ios_base& internal(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

showpos によって、正の数値に符号が表示されます。

マニピュレーターは実質的に str.setf(ios_base::internal,ios_base::adjustfield) を呼び出し、str を返します。

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

int main( void )
{
   using namespace std;
   float i = -123.456F;
   cout.fill( '.' );
   cout << setw( 10 ) << i << endl;
   cout << setw( 10 ) << internal << i << endl;
}
..-123.456
-..123.456

is_error_code_enum

template <> struct is_error_code_enum<io_errc> : public true_type { };

iostream_category

const error_category& iostream_category() noexcept;

出力幅に満たないテキストをストリーム フラッシュで左揃えに表示します。

ios_base& left(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

マニピュレーターは実質的に str.setf(ios_base::left, ios_base::adjustfield) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   double f1= 5.00;
   cout.width( 20 );
   cout << f1 << endl;
   cout << left << f1 << endl;
}
5
        5

make_error_code

error_code make_error_code(io_errc e) noexcept;

make_error_condition

error_condition make_error_condition(io_errc e) noexcept;

noboolalpha

bool 型の変数をストリームで 1 または 0 として表示するように指定します。

ios_base& noboolalpha(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、noboolalpha は有効です。

noboolalpha は実質的に str.unsetf(ios_base::boolalpha) を呼び出し、str を返します。

boolalphanoboolalpha の実行結果を元に戻します。

noboolalpha の使用例については、「boolalpha」を参照してください。

noshowbase

指定している数値表記の基底の設定をオフにします。

ios_base& noshowbase(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

noshowbase は既定でオンです。 showbase を使用して、数値表記の基底を示します。

マニピュレーターは実質的に str.unsetf(ios_base::showbase) を呼び出し、str を返します。

noshowbase の使用例については、「showbase」を参照してください。

noshowpoint

小数部分が 0 の浮動小数点数の整数部分のみを表示します。

ios_base& noshowpoint(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

noshowpoint は既定ではオンです。showpointprecision を使用して、小数点の後に 0 を表示します。

マニピュレーターは実質的に str.unsetf(ios_base::showpoint) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   double f1= 5.000;
   cout << f1 << endl;   // noshowpoint is default
   cout.precision( 4 );
   cout << showpoint << f1 << endl;
   cout << noshowpoint << f1 << endl;
}
5
5.000
5

noshowpos

正の数値に明示的に符号を付けないようにします。

ios_base& noshowpos(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

noshowpos は既定でオンです。

マニピュレーターは実質的に str.unsetf(ios_base::showpos) を呼び出し、str を返します。

noshowpos の使用例については、「showpos」を参照してください。

noskipws

入力ストリームで空白を読み取るようにします。

ios_base& noskipws(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、skipws は有効です。 入力ストリームでスペースが読み込まれると、バッファーの終了を通知します。

マニピュレーターは実質的に str.unsetf(ios_base::skipws) を呼び出し、str を返します。

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

int main() {
   using namespace std;
   string s1, s2, s3;
   cout << "Enter three strings: ";
   cin >> noskipws >> s1 >> s2 >> s3;
   cout << "." << s1  << "." << endl;
   cout << "." << s2 << "." << endl;
   cout << "." << s3 << "." << endl;
}

nounitbuf

出力をバッファーし、バッファーが一杯になると、出力を処理します。

ios_base& nounitbuf(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

unitbuf はバッファーが空ではないときに、バッファーを処理します。

マニピュレーターは実質的に str.unsetf(ios_base::unitbuf) を呼び出し、str を返します。

nouppercase

16 進数と指数表記の指数を小文字で表示します。

ios_base& nouppercase(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

マニピュレーターは実質的に str.unsetf(ios_base::uppercase) を呼び出し、str を返します。

nouppercase の使用例については、「uppercase」を参照してください。

oct

整数変数を 8 進表記で表示するように指定します。

ios_base& oct(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、整数変数は、10 進表記で表示されます。 dec および hex も整数変数の表示方法を変更します。

マニピュレーターは実質的に str.setf(ios_base::oct, ios_base::basefield) を呼び出し、str を返します。

oct の使用例については、「dec」を参照してください。

出力幅に満たないテキストをストリーム フラッシュで右揃えに表示します。

ios_base& right(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

left もテキストの両端揃えを変更します。

マニピュレーターは実質的に str.setf(ios_base::right, ios_base::adjustfield) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   double f1= 5.00;
   cout << f1 << endl;
   cout.width( 20 );
   cout << f1 << endl;
   cout.width( 20 );
   cout << left << f1 << endl;
   cout.width( 20 );
   cout << f1 << endl;
   cout.width( 20 );
   cout << right << f1 << endl;
   cout.width( 20 );
   cout << f1 << endl;
}
5
                   5
5
5
                   5
                   5

scientific

浮動小数点数を指数表記を使用して表示します。

ios_base& scientific(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、fixed 表記は浮動小数点数に対して有効です。

マニピュレーターは実質的に str.setf(ios_base::scientific, ios_base::floatfield) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   float i = 100.23F;

   cout << i << endl;
   cout << scientific << i << endl;
}
100.23
1.002300e+002

showbase

数値表記の基底を指定します。

ios_base& showbase(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

数値表記の基底は、decoct、または hex を使用して変更できます。

マニピュレーターは実質的に str.setf(ios_base::showbase) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   int j = 100;

   cout << showbase << j << endl;   // dec is default
   cout << hex << j << showbase << endl;
   cout << oct << j << showbase << endl;

   cout << dec << j << noshowbase << endl;
   cout << hex << j << noshowbase << endl;
   cout << oct << j << noshowbase << endl;
}
100
0x64
0144
100
64
144

showpoint

小数部分が 0 のときも浮動小数点数の整数部分と小数点の右側にある数字を表示します。

ios_base& showpoint(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、noshowpoint は有効です。

マニピュレーターは実質的に str.setf(ios_base::showpoint) を呼び出し、str を返します。

showpoint の使用例については、「noshowpoint」を参照してください。

showpos

正の数値に明示的に符号を付けます。

ios_base& showpos(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

noshowpos が既定の設定です。

マニピュレーターは実質的に str.setf(ios_base::showpos) を呼び出し、str を返します。

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

int main( )
{
   using namespace std;
   int i = 1;

   cout << noshowpos << i << endl;   // noshowpos is default
   cout << showpos << i << endl;
}
1
+1

skipws

入力ストリームで空白を読み飛ばします。

ios_base& skipws(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、skipws は有効です。 noskipws は、入力ストリームから空白を読み取るようにします。

マニピュレーターは実質的に str.setf(ios_base::skipws) を呼び出し、str を返します。

#include <iostream>
#include <string>

int main( )
{
   using namespace std;
   char s1, s2, s3;
   cout << "Enter three characters: ";
   cin >> skipws >> s1 >> s2 >> s3;
   cout << "." << s1  << "." << endl;
   cout << "." << s2 << "." << endl;
   cout << "." << s3 << "." << endl;
}
1 2 3
Enter three characters: 1 2 3
.1.
.2.
.3.

unitbuf

バッファーが空ではないときに、出力を処理します。

ios_base& unitbuf(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

endl もバッファーをフラッシュします。

既定では、nounitbuf は有効です。

マニピュレーターは実質的に str.setf(ios_base::unitbuf) を呼び出し、str を返します。

大文字

16 進数と指数表記の指数を大文字で表示します。

ios_base& uppercase(ios_base& str);

パラメーター

str
ios_base 型のオブジェクトまたは ios_base から継承した型への参照。

戻り値

str の派生元となるオブジェクトへの参照。

解説

既定では、nouppercase は有効です。

マニピュレーターは実質的に str.setf(ios_base::uppercase) を呼び出し、str を返します。

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

int main( void )
{
   using namespace std;

   double i = 1.23e100;
   cout << i << endl;
   cout << uppercase << i << endl;

   int j = 10;
   cout << hex << nouppercase << j << endl;
   cout << hex << uppercase << j << endl;
}
1.23e+100
1.23E+100
a
A