c++macosterminalcompiler-errorsxcode-debugger

Terminal error MacOS: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1634:1: note:


An error is generated when I try to run my C++ program:

#include <iostream>
#include <ctime> //standard c++ library of time.h 
using namespace std; 

class DateCplusplus{
private: 
    int _day, _month, _year; //define variable 
public: 
    void readValues(){
        cout<<"Enter the day value: "; 
        cin>>_day; 
        cout<<"\nEnter the month value: "; 
        cin>>_month; 
        cout>>_year; 
        _year = _year - 1900; 
    }

    int verifyValues(){
        if(_day>=1 && _day <=31 && _month>=1 && _month<= 12){
            return 1; 
        }
        return 0; 
    }

    int compareValues(){
        time_t now = time(0); 
        tm *ltm = localtime(&now); 
        if((_year == ltm -> tm_year) && (_month ==1 +ltm -> tm_mon) && (_day == ltm -> tm_mday)){
            return 1; 
        }
        return 0; 
    }

    int main(){
        DateCplusplus date; 
        date.readValues(); 
        cout<<"\nVerification of day and months values: "<<date.verifyValues()<<"\n"; 
        cout<<"\nComparision of the day, the month and the year with the System current Date: "<<date.compareValues(); 
        return 0; 
    }
};

The error showing in the terminal is: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1634:1: note: candidate template ignored: could not match 'basic_istream' against 'basic_ostream' operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)

Can you help me find my mistake ?

Thank you!


Solution

  • Your main function cannot be contained any classes so i extracted your main function from class DateCplusplus and you have syntax error that cou>>_year, it has to be cout<<_year.And you have to define _CRT_SECURE_NO_WARNINGS top of the code if you want to run.Because localtime is unsafe function.

    #define _CRT_SECURE_NO_WARNINGS
    
    
    #include <iostream>
    #include <ctime> 
    
    using namespace std;
    
    class DateCplusplus {
    private:
        int _day, _month, _year; //define variable 
    public:
        void readValues() {
            cout << "Enter the day value: ";
            cin >> _day;
            cout << "\nEnter the month value: ";
            cin >> _month;
            cout << _year;
            _year = _year - 1900;
        }
    
        int verifyValues() {
            if (_day >= 1 && _day <= 31 && _month >= 1 && _month <= 12) {
                return 1;
            }
            return 0;
        }
    
        int compareValues() {
            time_t now = time(0);
            tm* ltm = localtime(&now);
            if ((_year == ltm->tm_year) && (_month == 1 + ltm->tm_mon) && (_day == ltm->tm_mday)) {
                return 1;
            }
            return 0;
        }
    };
    
    
    
        int main() {
            DateCplusplus date;
            date.readValues();
            cout << "\nVerification of day and months values: " << date.verifyValues() << "\n";
            cout << "\nComparision of the day, the month and the year with the System current Date: " << date.compareValues();
            return 0;
        }