iostream 类库提供用于创建参数化的操控提供一组宏。 使用一个 int 或 long 参数的操控器是一种特殊情况。 创建接受单个 int 或 long 参数的输出流操控器 (如 setw),必须使用_Smanip 宏,在 <iomanip>定义。 此示例定义插入 null 指定数量的到流的一个 fillblank 移动:
示例
// output_stream_manip.cpp
// compile with: /GR /EHsc
#include <iostream>
#include <iomanip>
using namespace std;
void fb( ios_base& os, int l )
{
ostream *pos = dynamic_cast<ostream*>(&os);
if (pos)
{
for( int i=0; i < l; i++ )
(*pos) << ' ';
};
}
_Smanip<int>
__cdecl fillblank(int no)
{
return (_Smanip<int>(&fb, no));
}
int main( )
{
cout << "10 blanks follow" << fillblank( 10 ) << ".\n";
}