<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

noboolalpha 会取消 boolalpha 的效果。

示例

// 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

dec

指定以十进制计数法形式显示整数变量。

ios_base& dec(ios_base& str);

参数

str
ios_base 类型的对象的引用,或对从 ios_base 继承的类型的引用。

返回值

对派生 str 的对象的引用。

备注

默认情况下,整型变量以十进制计数法显示。

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

fixed

指定浮点数以自动设置小数点表示法显示。

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

指定以十六进制计数法形式显示整型变量。

ios_base& hex(ios_base& str);

参数

str
ios_base 类型的对象的引用,或对从 ios_base 继承的类型的引用。

返回值

对派生 str 的对象的引用。

备注

默认情况下,整型变量以十进制计数法显示。 decoct 也会改变整型变量显示的方式。

此操控器有效调用 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;

left

导致宽度比输出宽度短的文本在流刷新过程中显示时带有左边距。

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

boolalpha 会取消 noboolalpha 的效果。

示例

有关使用 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

仅显示浮点数(其小数部分为零)的整数部分。

ios_base& noshowpoint(ios_base& str);

参数

str
ios_base 类型的对象的引用,或对从 ios_base 继承的类型的引用。

返回值

对派生 str 的对象的引用。

备注

noshowpoint 默认为打开;使用 showpointprecision 显示小数点后的零。

此操控器有效调用 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

指定十六进制数字和科学计数法形式的指数以小写形式显示。

ios_base& nouppercase(ios_base& str);

参数

str
ios_base 类型的对象的引用,或对从 ios_base 继承的类型的引用。

返回值

对派生 str 的对象的引用。

备注

此操控器有效调用 str.unsetf(ios_base::uppercase),然后返回 str

示例

有关使用 nouppercase 的示例,请参阅 uppercase

oct

指定以八进制计数法形式显示整数变量。

ios_base& oct(ios_base& str);

参数

str
ios_base 类型的对象的引用,或对从 ios_base 继承的类型的引用。

返回值

对派生 str 的对象的引用。

备注

默认情况下,整型变量以十进制计数法显示。 dechex 也会改变整型变量显示的方式。

此操控器有效调用 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 的对象的引用。

注解

可使用 decocthex 更改数字的基数。

此操控器有效调用 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

显示浮点数的整数部分和小数点右侧的数字,即使小数部分为零。

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

大写

指定十六进制数字和科学计数法形式的指数以大写形式显示。

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