共用方式為


<ios> 函式

boolalpha

指定 bool 型態的變數在資料串流中顯示為 truefalse

ios_base& boolalpha(ios_base& str);

參數

str
ios_base 類型之物件的參考,或對繼承自 ios_base 之類型的參考。

傳回值

衍生 str對象的參考。

備註

bool 類型的變數預設會顯示為 1 或 0。

boolalpha 會有效地呼叫 str.setfios_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

指定整數變數會以基底 10 標記法顯示。

ios_base& dec(ios_base& str);

參數

str
ios_base 類型之物件的參考,或對繼承自 ios_base 之類型的參考。

傳回值

衍生 str對象的參考。

備註

整數變數預設會使用以 10 為底數的方式來顯示。

dec 會有效地呼叫 str.setfios_base::decios_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 會讓浮點數以科學標記法顯示。

操作工具會有效地呼叫 strsetfios_base::fixedios_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 為底數的標記法來顯示。 decoct 也會變更整數變數的顯示方式。

操作工具實際上會呼叫 strsetfios_base::hexios_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 類型的變數在資料流中顯示為 0 或 1。

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

指定以基底 8 標記法顯示整數變數。

ios_base& oct(ios_base& str);

參數

str
ios_base 類型之物件的參考,或對繼承自 ios_base 之類型的參考。

傳回值

衍生 str對象的參考。

備註

整數變數預設會使用以 10 為底數的標記法來顯示。 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。

uppercase

指定以大寫顯示十六進位數字和科學標記法中的指數。

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