【问题标题】:Terminal error MacOS: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1634:1: note:终端错误 MacOS:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1634:1:注意:
【发布时间】:2020-02-14 13:05:04
【问题描述】:

当我尝试运行我的 C++ 程序时产生错误:

#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; 
    }
};

终端显示的错误是: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/istream:1634:1:注意: 候选模板被忽略:无法将“basic_istream”与“basic_ostream”匹配 运算符>>(basic_istream<_chart _traits>& __is, bitset<_size>& __x)

你能帮我找出我的错误吗?

谢谢!

【问题讨论】:

    标签: c++ macos terminal compiler-errors xcode-debugger


    【解决方案1】:

    你的主函数不能包含任何类,所以我从 DateCplusplus 类中提取了你的主函数,你有 cou>>_year 的语法错误,它必须是 cout

    #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;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 2012-05-09
      • 2019-03-30
      • 2016-12-10
      • 2018-05-06
      • 2015-02-08
      • 2018-05-10
      相关资源
      最近更新 更多