64,682
社区成员
发帖
与我相关
我的任务
分享
#include <iomanip>
#include <iostream>
using namespace std;
class Fun //类 Fun
{
friend ostream & operator < <(ostream & , Fun ); //友元函数
};
ostream & operator < <(ostream & os, Fun f)
{
os.setf(ios::left);
return os;;
}
void main()
{
Fun fun;
cout < < setfill('*') < < setw(10) < <12345 < <" ";
cout < < fun < < setw(10) < < 54321 < < endl;
}
后来我发现程序改成如下就没有问题。不知道什么道理,各位大哥请指教。
#include <iomanip>
#include <iostream>
using namespace std;
class Fun
{
friend ostream & operator < <(ostream & os, Fun f)
{
os.setf(ios::left);
return os;;
}
};
void main()
{
Fun fun;
cout < < setfill('*') < < setw(10) < <12345 < <" ";
cout < < fun < < setw(10) < < 54321 < < endl;
}