C ++中的操纵器 [英] manipulators in c++

查看:86
本文介绍了C ++中的操纵器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为上课日期写一个操纵器,
cout<< dmy<< obj;
它将首先打印日期,月份和年份.

i need to write a manipulator for class date,
cout << dmy << obj;
it will first print date, month and year. Is there any one cal help me..................?

推荐答案

您是否正在寻找运算符重载?像这样的东西:
Are you looking for operator overloading? Something like:
ostream &operator<<( ostream &out, const DMY &dmy )
{
  out << dmy.Date() << dmy.Month() << dmy.Year();
  return out;
}




也许我有点误解了你的问题.这是一个很好的链接,向您展示 WritingStreamManipulators.html [ ^ ]




maybe I misunderstood your question a bit. Here is a good link to show you how WritingStreamManipulators.html[^]


我的问题是关于操纵器的. DMY是个错综复杂的东西,那就是我要写的.

我已经超负荷了<<操作员...

ostream&operator<<(ostream&out,日期d)
{
返回<< d.day()<< d.month()<< d.year();
}
但是,cout<< MYD<< d;
将给出输出,如月,年和日期. MYD是我需要写的错别字.如果你知道告诉我...

谢谢尼古拉斯先生
My questions is about manipulators . DMY is a malipulator, thats i want to write.

i have already over load<< operator...

ostream &operator<<(ostream &out, date d)
{
return out << d.day() << d.month() << d.year();
}
but, cout << MYD << d;
will give the output like month, year & date. MYD is the malipulator i need to write . if you know tell me...

Thanks Mr.Niklas


这篇关于C ++中的操纵器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆