hi people I have a project that requires me to use time.h in animation. can anyone show me a simple code of animation using time.h???

Basically all you need the time.h library for is slowing things down enough to produce the effect of animation:

#include <iostream>
#include <ctime>

void pause_execution(double seconds)
{
    std::time_t start = std::time(0);
    
    while (std::difftime(std::time(0), start) < seconds)
        ;
}

int main()
{
    std::cout << "Paused" << std::flush;
    
    for (int i = 0; i < 10; i++) {
        pause_execution(1);
        std::cout << ". " << std::flush;
    }
    
    std::cout << "\nDone\n";
}

Note that a busy loop as shown in pause_execution() is an exceptionally bad design, but standard C++ doesn't presently offer a way of putting the current thread of execution to sleep such that other threads can make use of the downtime. However, for educational purposes, a busy loop is fine. Just be aware that it's very antisocial in a multitasking system.

Thanks narue,is there a way you can use namespace std in the code above and avoid using the std::before the cout??? I also need to use the time.h so please include it at the top.

I doubt she's going to do everything for you. Unless she's in a really really really good mood.

is there a way you can use namespace std in the code above and avoid using the std::before the cout???

So you can turn it in for a grade without doing any work? Hell no. I already solved the majority of your problem, asking me to do the unethical shit work of making code that's not yours look like yours is insulting. Quite frankly, I'm regretting helping you at all at this point.

I also need to use the time.h so please include it at the top.

I did use it. The only difference between <ctime> and <time.h> is the former places names in the std namespace and the later is technically deprecated.

Unless she's in a really really really good mood.

When have I ever been in a really really really good mood? ;)

I guess I'll have to use to as it is,thanks alot for your contribution

wow, i don't know you max hydes but i tend to think you are in shibwabo's class of 2011. your question has solved my problemmo. thanks Narue

ratatat u can also include windows.h and use sleep to animate eg...

#include<iostream>
#include<windows.h>
using namespace std;
void main()
{
    cout<<"this is fun";
    Sleep(200);
    cout<<"I like";
}

try that

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.