Implementing a Yearmonth class Recently I wrote a program that was required to handle year and month data and so I wrote this class to encapsulate that handling.  What I needed was a way to initialize the Yearmonth object based on the current local time, and allow a simple method of calculating future Yearmonth values based on a duration in months.  This sample code illustrates how I use it:

ymtest.cpp

#include &lt;iostream&gt;
#include "Yearmonth.h"

int main()
{
    YM::Yearmonth ym;    // today
    std::cout &lt;&lt; ym &lt;&lt; '\n';
    ym += 2;         // 2 months from now
    std::cout &lt;&lt; ym &lt;&lt; '\n';
    ym += 14;        // test year increment
    std::cout &lt;&lt; ym &lt;&lt; '\n';
}


Yearmonth.h

#ifndef YEARMONTH_H
#define YEARMONTH_H
#include &lt;iostream&gt;

namespace YM {
class Yearmonth
{
public:
    // construct with today's year and month
    Yearmonth();
    // construct with year, month (1=Jan, 12=Dec)
    Yearmonth(unsigned ayear, unsigned amonth);
    // increment by given number of months
    Yearmonth &amp;operator+=(const unsigned mon);
    // return year
    unsigned year() const;
    // return month (1=Jan, 12=Dec)
    unsigned month() const;
    // prints to ostream.  E.g. 2014 Dec ==&gt; "201412"
    friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;out, const Yearmonth &amp;ym);
private:
    unsigned myyear;
    unsigned mymonth;
};
}
#endif //YEARMONTH_H


Yearmonth.cpp

#include &lt;ctime&gt;
#include "Yearmonth.h"

namespace YM {
Yearmonth::Yearmonth()
{
    time_t tt;
    time(&amp;tt);
    tm *t = localtime(&amp;tt);
    myyear = t-&gt;tm_year + 1900;
    mymonth = t-&gt;tm_mon;
}

Yearmonth::Yearmonth(unsigned ayear, unsigned amonth)
    : myyear(ayear), mymonth(amonth-1)
{
    myyear += mymonth/12;
    mymonth %= 12;
}

unsigned Yearmonth::year() const
{
    return myyear;
}

unsigned Yearmonth::month() const
{
    return mymonth+1;
}

Yearmonth &amp;Yearmonth::operator+=(const unsigned mon)
{
    mymonth += mon;
    myyear += mymonth/12;
    mymonth %= 12;
    return *this;
}

std::ostream&amp; operator&lt;&lt;(std::ostream &amp;out, const Yearmonth &amp;ym)
{
    return out &lt;&lt; ym.myyear * 100 + ym.mymonth+1;
}
}


The class seems sufficient for my needs and everything works.  Have I missed anything important?
I only have a few small remarks to make:


In your header file, don't include &lt;iostream&gt;: include &lt;iosfwd&gt; instead which contains the forward declarations for every type in &lt;iostream&gt;.
Also, you only use std::ostream in your source file, so you could simply include &lt;ostream&gt; there.
Several times, you compute mymonth / 12 and mymonth % 12. If your class is designed to be used intensively, you could consider using std::div(mymonth, 12) which will compute both values at once and may therefore be slightly faster (if you really need it).
You may want to prefix time_t, time, tm and localtime with std::. Them coming from the C standard library doesn't prevent you to use std::.
Using a const unsigned parameter seems pretty useless. I don't have strong opinions on the const on value parameters, but you could safely drop it since it adds little value.