how to use time.h

Hello guys,how i can use ccc_time.h?
when compiling it gets me an error : [Error] ccc_time.h: No such file or directory
its <ctime> in c++

so #include<ctime>

if you are looking for a stopwatch, consider <chrono>. If you want date and time, I think ctime is still the go-to tool, but I don't do date-time manipulation very often.


in the code I add #include<ctime> but it still doesn't work
Do you have ccc_time.h and ccc_time.cpp?
Is ccc_time.h in your include path?
Remember to also compile and link to ccc_time.cpp.
in the code I add #include<ctime> but it still doesn't work

then you need to explain better.
do you have some custom alternate files with odd names? If so, follow dutch's advice.
if its ctime as your title indicated, what 'didnt work'. Did it fail to compile? Did it compile but crash when you run it? Maybe it ran but gave weird answers.

your question is effectively: "I wrote a program and it did not work. Why not?!".
No i dont have have ccc_time.h and ccc_time.cpp?
what should I do?
Somewhere in your code is the text "ccc_time.h".

Find it. Remove it.
Okay this is the code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

#include "ccc_time.h"

int main()
{  Time now;
   Time day_end(23, 59, 59);
   long seconds_left = day_end.seconds_from(now);

   cout << "There are " << seconds_left
        << " seconds left in this day.\n";

   return 0;
}



Why this code doesn't work and it gives me an error [Error] ccc_time.h: No such file or directory
Why this code doesn't work

You can't magically use a file just by mentioning it.
You actually need to have it and it needs to be in the correct location.

Why do you want to use ccc_time.h?
You can get the files (ccc_time.h and ccc_time.cpp) here: https://github.com/jhansen317/cpp
Last edited on
Hello popcornaaa,

I think something like this is what you are trying to do:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <iomanip>
#include <ctime>

using namespace std;

int main()
{  
   double seconds_left{};
   struct tm endDay;
   time_t now = time(&now);
   
   endDay.tm_hour = 23;
   endDay.tm_min = 59;
   endDay.tm_sec = 59;
   
   seconds_left = difftime(now, mktime(&endDay));

   std::cout << fixed << noshowpoint << setprecision(0);
   
   cout << "There are " << seconds_left
        << " seconds left in this day.\n";

   return 0;
}

And produces the output of:

There are 3791491640 seconds left in this day.



Andy
Hello popcornaaa,

The problem with ("ccc_time.h") has already been covered except to say that this file should be in the current working directory when running the program. This should be different subdirectories depending on how you run the program.

Before I get into why the previous post has such a large number and what I have learned I need to know if you have figured it out or not.

Andy
Topic archived. No new replies allowed.