A sleep problem

This is a discussion on A sleep problem within the C++ Programming forums, part of the General Programming Boards category; void introtxt(char* letter) { cout << letter; Sleep(40); } this doesnt work on my compiler. i define the letters, but ...

  1. #1
    Ryan
    Guest

    A sleep problem

    void introtxt(char* letter) {
    cout << letter;
    Sleep(40);
    }


    this doesnt work on my compiler. i define the letters, but it sleeps for like 10 seconds and then print all th letters fast and quits. why?

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You'll need to flush the output -

    cout << letter << flush;

    To get help with Sleep() you'll have to state your compiler as it's not a standard function.

  3. #3
    Unregistered
    Guest

    Talking Do this!!!

    #include <iostream>
    #include <ctime>
    using namespace std;

    void sleep()
    {
    double seconds = 1.5;
    clock_t timer;
    timer = clock() + seconds * 1000;
    while (clock() < timer) {}
    }

    int main()
    {
    cout << "I am now!!!" << endl;
    sleep();
    cout << "I am 1.5 seconds later" << endl;
    return 0;
    }

    I think this should work, if I remember I got it correct
    Good luck!!

  4. #4
    Unregistered
    Guest

    Talking Unregistered again!!

    If you want to one char printed, with a pause after each character, then you need to make a for loop, and.. well it will look something like this.

    char Text[] = "Hello my name is Rocky";

    for (int i = o;Text[i] != '\0';i++)
    {
    cout << Text[i];
    sleep();
    }

  5. #5
    Unregistered
    Guest

    Thumbs up Think im right!!

    I think that Im right, but if im wrong, I hope that someone will correct me!!

  6. #6
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Sleep(40);


    that would be 40 milliseconds.... pretty fast I should think.

    1000 milliseconds equals 1 second.

    hmmm....
    Blue

  7. #7
    Unregistered
    Guest

    Talking I think that...

    I think that it´s more fun to do it with clock_t instead..

    But if you prefer sleep(); then thats cool to!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. sleep() problem when Time Hits Midnight
    By seemarj83 in forum C Programming
    Replies: 4
    Last Post: 05-25-2007, 03:32 AM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21