共用方式為


<ostream> 函式

這些是 中 <ostream> 定義的全域範本函式。 如需成員函式,請參閱 basic_ostream 類別 檔。

endl
ends
flush
swap

endl

結束一行並清除緩衝區。

template class<Elem, Tr>
basic_ostream<Elem, Tr>& endl(
   basic_ostream<Elem, Tr>& Ostr);

參數

Elem
元素類型。

Ostr
類型 為 basic_ostream 的物件。

Tr
字元特性。

傳回值

類型 為 basic_ostream 的物件。

備註

操作工具會呼叫 Ostr put Ostr . widen ('\n')),然後呼叫 Ostr flush 。 它會傳 回 Ostr

範例

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

int main( )
{
   using namespace std;
   cout << "testing" << endl;
}
testing

結尾

結束字串。

template class<Elem, Tr>
basic_ostream<Elem, Tr>& ends(
   basic_ostream<Elem, Tr>& Ostr);

參數

Elem
元素類型。

Ostr
basic_ostream 類型的物件。

Tr
字元特性。

傳回值

basic_ostream 類型的物件。

備註

操作工具會呼叫 Ostr put (Elem '\0'))。 它會傳 回 Ostr

範例

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

int main( )
{
   using namespace std;
   cout << "a";
   cout << "b" << ends;
   cout << "c" << endl;
}
ab c

flush

清除緩衝區。

template class<Elem, Tr>
basic_ostream<Elem, Tr>& flush(
   basic_ostream<Elem, Tr>& Ostr);

參數

Elem
元素類型。

Ostr
basic_ostream 類型的物件。

Tr
字元特性。

傳回值

basic_ostream 類型的物件。

備註

操作工具會呼叫 Ostr flush 。 它會傳 回 Ostr

範例

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

int main( )
{
   using namespace std;
   cout << "testing" << flush;
}
testing

swap

交換兩個 basic_ostream 物件的值。

template <class Elem, class Tr>
void swap(
   basic_ostream<Elem, Tr>& left,
   basic_ostream<Elem, Tr>& right);

參數

Elem
元素類型。

Tr
字元特性。

left
basic_ostream 物件的 lvalue 參考。

right
basic_ostream 物件的 lvalue 參考。

備註

樣板函式 swap 會執行 left.swap(right)

另請參閱

<ostream>