Problems.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wrycu
    New Member
    • Sep 2006
    • 9

    Problems.

    Hello people.

    I am pretty new to C++, but not very new to coding. I would like to have a C++ program do something at a certain date and time. I currently have the code:
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    string timee;
    
    int main()
    {
        timee="Sun 09/03/2006";
        if (system("date /t")==timee)
        {
           cout<<"I win.\n";
        }
        cout<<timee;
        system("pause");
        return 0;
    }
    Im getting an error saying i cannot compare the two, or there is no room for operator== in that statement. I just need to get the time, and say... if its a certian time, do something. Can anyone help?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Look up the function system, it does not return the output of the command run, it returns a int giving a success flag.

    I suggest that you look up the time functions in C rather than trying to call out to the OS.

    Look up functions

    asctime - Convert time from type struct tm to character string.

    clock - Return elapsed CPU time for process.

    ctime - Convert time from type time_t to character string.

    difftime - Compute difference between two times.

    gmtime - Convert time from type time_t to struct tm

    localtime - Convert time from type time_t to struct tm with local correction.

    mktime - Convert time to calendar value.

    strftime - Format date-and-time string for international use.

    time - Get current system time as type time_t.

    Comment

    • Rakesh Mutharaju
      New Member
      • Sep 2006
      • 14

      #3
      #include<time.h >
      #include<stdio. h>
      #include<conio. h>

      void main()
      {
      long time1;
      struct tm strtm;
      clrscr();
      time(&time1);
      strtm = *localtime(&tim e1);
      printf(" \n time %ld",time1);

      printf(" \n time.tm_sec %d ",strtm.tm_sec) ;
      printf(" \n time.tm_min %d",strtm.tm_mi n);
      printf(" \n time.tm_hour %d",strtm.tm_ho ur);
      printf(" \n time.tm_mday %d",strtm.tm_md ay);
      printf(" \n time.tm_mon %d",strtm.tm_mo n);
      printf(" \n time.tm_year %d", strtm.tm_year);
      printf(" \n time.tm_wday %d",strtm.tm_wd ay);
      getch();
      }


      output:

      time 1157402802
      time.tm_sec 42
      time.tm_min 46
      time.tm_hour 16
      time.tm_mday 4
      time.tm_mon 8
      time.tm_year 106
      time.tm_wday 1

      This code will get the current system local time and print the details..as shown above

      so for ur verification..

      compare the details accordingly.. and do the rest.

      struct tm... variables..
      int tm_sec; seconds after the minute
      int tm_min; minutes after the hour
      int tm_hour; hours since midnight
      int tm_mday; day of the month
      int tm_mon; months since January
      int tm_year; years since 1900
      int tm_wday; days since Sunday
      int tm_yday; days since January 1
      int tm_isdst; Daylight Saving Time flag

      Comment

      • Wrycu
        New Member
        • Sep 2006
        • 9

        #4
        Sweet, thanks.

        Comment

        Working...