- 论坛徽章:
- 0
|
UNIX下C++调用标准C函数应注意什么?
多谢各位大虾!
- #include <iostream.h>;
- #include <stdlib.h>;
- #include <time.h>;
- #include <stdio.h>;
- class Date
- {
- public:
- Date()
- {
- year = 0;
- month = day = 1;
- };
- Date(int d, int m, int y)
- {
- year = y;
- month = m;
- day = d;
- };
- void display()
- {
- cout << year << "年" << month << "月" << day << "日" << endl;
- };
- Date operator +(const int &days);
- private:
- int year;
- int month;
- int day;
- };
- inline Date Date::operator +(const int &days)
- {
- struct tm stcTime, *newday;
- time_t tTimes1 = 0, tTimes2 = 0;
-
- stcTime.tm_year = year;
- stcTime.tm_mon = month - 1;
- stcTime.tm_mday = day;
- stcTime.tm_hour = 0;
- stcTime.tm_min = 0;
- stcTime.tm_sec = 0;
-
- tTimes1 = mktime( &stcTime );//[color=red]这里返回-1,不知何问题?[/color]
-
- tTimes2 = days*24*60*60;
- newday = localtime( &tTimes2 );//[color=red]这里应该是newday->;tm_mday == 21,可实际是newday->;tm_mday == 22[/color]
- cout << newday->;tm_mday << "\t" << newday->;tm_mon + 1 << "\t" << newday->;tm_year + 1900 << endl;
- cout << tTimes1 << "\t" << tTimes2 << endl;
- tTimes2 += tTimes1;
-
- newday = localtime( &tTimes2 );
-
- return Date(newday->;tm_mday, newday->;tm_mon + 1, newday->;tm_year + 1900);
- }
- void main()
- {
- Date olddate(2, 20, 1998);
- Date newdate;
-
- olddate.display();
- newdate = olddate + 21;
- newdate.display();
- }
复制代码
不知是不是编译器的问题?
/opt/CC/bin/CC -Aa -g -w -o /opt/cnc/bin/Date Date.o -lm -lc
请指教! |
|