Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:11:48+00:00 2026-06-05T15:11:48+00:00

I am using C++ in Ubuntu with codeBlocks, boost 1.46 in GCC 4.7 [

  • 0

I am using C++ in Ubuntu with codeBlocks, boost 1.46 in GCC 4.7 [ yield_k.hpp ]

I get this compile time error:

error : Sleep was not declared in this scope

Code:

#include <iostream>
using namespace std;
int main() { 
  cout << "nitrate";
  cout << flush;
  sleep(1000);
  cout << "firtilizers";
  return 0;
}

How do I resolve this error? I want the program to hang for 1 second.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:11:49+00:00Added an answer on June 5, 2026 at 3:11 pm

    Sleep is a Windows function.

    For Unix, look into using nanosleep (POSIX) or usleep (BSD; deprecated).

    A nanosleep example:

    void my_sleep(unsigned msec) {
        struct timespec req, rem;
        int err;
        req.tv_sec = msec / 1000;
        req.tv_nsec = (msec % 1000) * 1000000;
        while ((req.tv_sec != 0) || (req.tv_nsec != 0)) {
            if (nanosleep(&req, &rem) == 0)
                break;
            err = errno;
            // Interrupted; continue
            if (err == EINTR) {
                req.tv_sec = rem.tv_sec;
                req.tv_nsec = rem.tv_nsec;
            }
            // Unhandleable error (EFAULT (bad pointer), EINVAL (bad timeval in tv_nsec), or ENOSYS (function not supported))
            break;
        }
    }
    

    You will need <time.h> and <errno.h>, available in C++ as <ctime> and <cerrno>.

    usleep is simpler to use (just multiply by 1000, so make it an inline function). However, it’s impossible to guarantee that that sleeping will occur for a given amount of time, it’s deprecated, and you need to extern "C" { }-include <unistd.h>.

    A third choice is to use select and struct timeval, as seen in http://source.winehq.org/git/wine.git/blob/HEAD:/dlls/ntdll/sync.c#l1204 (this is how wine emulates Sleep, which itself is just a wrapper for SleepEx).

    Note: sleep (lowercase ‘s’), whose declaration is in <unistd.h>, is not an acceptable substitute, since its granularity is seconds, coarser than that of Windows’ Sleep (uppercase ‘s’), which has a granularity of milliseconds.

    Regarding your second error, ___XXXcall is a MSVC++-specific token (as are __dllXXX, __naked, __inline, etc.). If you really need stdcall, use __attribute__((stdcall)) or similar to emulate it in gcc.

    Note: unless your compile target is a Windows binary and you’re using Win32 APIs, use of or a requirement for stdcall is A Bad Sign™.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I am using Ubuntu The newer python version is not in the apt-get
I'm using Code::Blocks to compile a shared library on Ubuntu. When I make a
I'm using Ubuntu 8.10 (Intrepid Ibex) and compiling C++ files with GCC, but when
I am using Ubuntu 9.10 beta, whose repositories contain boost 1.38. I would like
I am using Ubuntu 9.10 For a particular piece of code I require GCC
I'm using Ubuntu 11.04, rvm and Heroku. When I'm doing this heroku logs --tail
i am using ubuntu and want to know the creation time of a file
I'm trying to get sqlite3 c-api to compile under windows with code:blocks/gcc mingw compiler
I am using boost 1.45.0 on Ubuntu with Code::Blocks as my IDE, and I
I am using g++ in CodeBlocks IDE in Ubuntu. I am new to STL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.