小编may*_*y00的帖子

类中的字符串// C++

我是C++的新手,并且在课堂上遇到麻烦

Date.cpp:

#include "stdafx.h"
#include "Date.h"
#include <sstream>
#include <string>

using namespace std;

Date::Date(int day,int month,int year )
{
    setDate(day,month,year);
}

void Date::setDate(int day,int month,int year)
{
    this->day = day;
    this->month = month;
    this->year = year;
}

string Date::printIt()
{
    std::stringstream res;

    res<<this->day<<"/";
    res<<this->month<<"/";
    res<<this->year;

    return res.str;
}

Date operator+(const Date &date,int day)
{
    Date newDate(date.day,date.month,date.month);

    newDate.day += day;

    if(newDate.day > 30)
    {
        newDate.day%=30;
        newDate.month+=1;

        if(newDate.month>=12)
        {
            newDate.month%=30;
            newDate.year+=1;
        }
    }

    return newDate;
}
Run Code Online (Sandbox Code Playgroud)

Date.h:

#ifndef DATE_H
#define DATE_H 

using …
Run Code Online (Sandbox Code Playgroud)

c++ string class function

1
推荐指数
1
解决办法
687
查看次数

标签 统计

c++ ×1

class ×1

function ×1

string ×1