Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:04:10+00:00 2026-06-18T09:04:10+00:00

Okay so I’m building a Date class class Date { private: int d; int

  • 0

Okay so I’m building a Date class

class Date
{
    private:
    int d;
    int m;
    int y;

 public:
    Date();
    Date(int&, int&, int&);
    Date(const Date&);
    bool isLeap();
    void setDay(int& day)
    {d = day;}
    void setMonth(int& month)
    {m = month;}
    void setYear(int& year)
    {y = year;}
    int getDay() const
    {return d;}
    int getMonth() const
    {return m;}
    int getYear() const
    {return y;}
    void print(ofstream& outfile)
    {
        outfile << "The date in this class is: " <<  << m << "/" << d << "/" << y;
    }

    Date operator= (const Date&);
};

I created an ofstream in main and opened the file. I’m also making sure to pass it by reference! Every time I try to compile I get the error: expected primary-expression before ‘<<‘ token message… Here is my main function. Let me know if I need anything else.

    int main()
{
    int day;
    int month;
    int year;
    Date d1;
    ofstream outfile("Print.txt");
    int maxDays;

    Date d2 = d1;

    cout << "Please enter the 4 digit year: ";
    cin >> year;
    if (year > 0)
    {
        d1.setYear(year);
        cout << "Please enter the 2 digit month: ";
        cin >> month;
        if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
            maxDays = 31;
        else if (month==4||month==6||month==9||month==11)
            maxDays = 30;
        else if (month==2&&d1.isLeap()==false)
            maxDays = 28;
        else if (month==2&&d1.isLeap()==true)
            maxDays = 29;
        if (month < 12)
        {
            d1.setMonth(month);
            cout << "Please enter the 2 digit day: ";
            cin >> day;
            if (day <= maxDays)
                d1.setDay(day);
            else
            {
                cout << "Invalid input, will set to default." << endl;
                d1 = d2;
            }


        }
        else
        {
            cout << "Invalid input, will set to default." << endl;
            d1 = d2;
        }
    }

    else
    {
        cout << "Invalid input, will set to default." << endl;
        d1 = d2;
    }

    d1.print(outfile);

    if(d1.isLeap()==true)
        cout << "This is a leap year\n";
    if(d1.isLeap()==false)
        cout << "This is not a leap year\n";

    cout << "The date is " << d1.getDay() << "/" << d1.getMonth() << "/" << d1.getYear() << endl;

    outfile.close();

    return 0;
}

Any help would be greatly appreciated…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:04:11+00:00Added an answer on June 18, 2026 at 9:04 am

    This line:

    outfile << "The date in this class is: " <<  << m << "/" << d << "/" << y;
    

    Has two << with nothing between them.

    Editorial note: I’m guessing you’re using GCC, based on the error message you mention. You might be interested to try clang, which produces a much better error message in this case:

    example.cpp:30:54: error: expected expression
        outfile << "The date in this class is: " <<  << m << "/" << d << "/" << y;
                                                         ^
    1 error generated.
    

    If you’re a beginner, it might save you a lot of time over chasing down the bizarro GCC error messages that can be generated by minor syntax errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this is the case: I got a generic base-class which I need to
Okay that title may not have been too clear, I am building a site
Okay, so, for example, let's say I have an abstract class called Vehicle. The
Okay, I asked this question the other day, and it was closed due to
Okay, my code is currently: public MySqlDataReader CreateQuery(string queryString, string connectionString ) { using
Okay so the basically I'm building an application to connect to xero on the
Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess
Okay, I have the following create action #posts_controller, nested resource under discussions def create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.